Android SoundPool 剪短声音文件

发布于 2024-10-04 23:44:20 字数 687 浏览 7 评论 0原文

我对 Android 还很陌生,所以要温柔一点!

我有以下代码,(我认为)应该只播放“developersshort”。

public constructor(Context context){
    this.context = context;
    soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC,0);
    soundPoolMap = new HashMap<Integer, Integer>();
    soundPoolMap.put(1, soundPool.load(this.context, 
        R.raw.developersshort, 1));         
}

public void run() {
    soundPool.play(soundPoolMap.get(1), 1, 1, 1, 0, 1f);
}

[为了弄清楚发生了什么,它当前播放史蒂夫鲍尔默反复喊“开发人员”的混音!声音文件大小约为 90KB。]

当我在模拟器中运行我的应用程序并按下按钮触发声音时,它会显示“开发人员开发人员开发人员...”等等,就像我所期望的那样。

然而,当我将它部署到手机上时,我只听到一次类似“velop”的声音,然后声音停止了。

我不知道发生了什么,有什么想法吗?

多谢!

I'm fairly new to Android so be gentle!

I have the following code, which should (I think) just play "developersshort".

public constructor(Context context){
    this.context = context;
    soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC,0);
    soundPoolMap = new HashMap<Integer, Integer>();
    soundPoolMap.put(1, soundPool.load(this.context, 
        R.raw.developersshort, 1));         
}

public void run() {
    soundPool.play(soundPoolMap.get(1), 1, 1, 1, 0, 1f);
}

[To try to figure out what's going on, it currently plays that remix of Steve Ballmer shouting "developers" repeatedly! The sound file is ~90KB in size.]

When I run my app in the emulator, and press the button to trigger the sound, it says "developers developers developers..." etc etc, like I would expect.

However, when I deploy it to my phone, all I hear something like "velop" once, and then the sound stops.

I have NO idea what is going on, any ideas?

Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

酒中人 2024-10-11 23:44:21

您的音频文件是 .ogg 文件吗? SoundPool 似乎其他格式存在问题。如果这不起作用,您可能需要使用较小的音频文件进行测试。当我的音频文件超过 60kb 时,我遇到了一些故障。

Is your audio file a .ogg file? It seems like other formats have issues with SoundPool. If that doesn't work you may want to test it with a smaller audio file. I had some glitches when my audio file was over 60kb.

相思故 2024-10-11 23:44:21

您是否尝试过重新采样声音文件???

在此之前我的声音文件被剪切。但我已经将 m4a 从 44KHz 转换并重新采样为 22KHz,现在它可以正常工作而不会被剪切。参考这个:再次关于SoundPool的内存问题

所以尝试同样的。

希望它对你有用。

Have you try with resampling the sound file ???

Before that my sound file getting cut. But i have converted and resample that m4a from 44KHz to 22KHz and now it works without getting cut. refer this : and again about memory issues with SoundPool

So try like same.

Hope it will works for you.

音盲 2024-10-11 23:44:21

存储上 60kb,或堆上 2mb,已解码,因为纯波可能是极限,是的。
确保您使用的时间不超过一秒或类似的时间。

soundpool确实需要小文件。阅读 SDK 页面。

60kb on storage, or 2mb on the heap, decoded, as pure wave MIGHT be the limits, yes.
make sure you dont use anything longer than a second or something like that.

soundpool really needs small files. read the SDK page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文