Android版的Soundpool有时播放声音时,两次循环参数设置为0 [英] Android SoundPool sometimes plays sound twice when loop param is set to 0
问题描述
下面是我在做什么:
private SoundPool pool;
private int soundId;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// new SoundPool with three channels, STREAM_MUSIC, default quality
pool = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);
// load sound with current context, click resource, priority 1
soundId = pool.load(this, R.raw.click, 1);
// originally I wasn't using this but it seemed to help a bit
// set no loop for soundId
pool.setLoop(soundId, 0);
}
private void play()
{
Log.v(TAG, "Play the sound once!");
// half volume L & R, priority 1, loop 0, rate 1
pool.play(soundId, 0.5f, 0.5f, 1, 0, 1);
}
@Override
public void onDestroy()
{
super.onDestroy();
// release the pool
pool.release();
}
本来我是使用点击声音.wav文件,并会出现90%的时间的问题。我说setLoop,它似乎减少它一点点。
Originally I was using a .wav file for the click sound and the problem would occur 90% of the time. I added setLoop and it appears to reduce it a tiny bit.
我是这么认为的我转换为.mp3文件可能是与装载.wav文件的一个问题。现在的问题发生的5%的时间,但它仍然发生。我建了有和没有setLoop电话,看来,包括它有助于一点点。
I thought it might be a problem with loading .wav files so I converted the file to .mp3. Now the problem happens 5% of the time, but it still happens. I built with and without the setLoop call and it appears that including it helps a tiny bit.
正如你可以看到我已经添加了一个调试日志信息,以确保我不小心调用播放功能的两倍。根据日志输出,声音只打过一次,但我听到声音的两倍。
As you can see I have added a debug log message to ensure that I am not accidentally calling the play function twice. According to the log output, the sound is only played once but I hear the sound twice.
我也用几种不同的声音文件。某些文件似乎比其他人更频繁地重复。我没有看到任何相关性,除了它与.wav文件发生更频繁。
I have also used several different sound files. Some of the files seem to repeat more frequently than others. I don't see any correlations except it happens more frequently with .wav files.
我看到发生在三星的连续运行问题2.1(分和放大器;目标API:7级)。我没有经历过任何市场中的应用,我在同一设备上下载任何额外的循环。不幸的是,我没有其他设备进行测试。
I see the problem happening on Samsung Continuum running 2.1 (min & target API: level 7). I haven't experienced any extra looping with any market apps I've downloaded on the same device. Unfortunately, I don't have other devices to test with.
我只发现了另外一个人遇到这个问题,他或她还使用了三星的设备。
I have only found one other person experiencing this issue and he or she was also using a Samsung device.
下面是其他问题的链接报道:
Here is a link to the other issue reported:
在这一点上我想我会尽力做一个发布版本,看看它仍然发生,然后可能转化为.OGG格式。之后,我可能会尝试切换到MediaPlayer的,看我是否得到相同的结果。
At this point I guess I'll try making a release build to see if it still happens and then maybe convert to .ogg format. After that I'll probably try switching to MediaPlayer to see if I get the same results.
感谢您的帮助。
推荐答案
我遇到同样的问题,同时为我的10 XPERIA mini pro的(Android 2.1系统)。这个问题的答案接受为我工作:
I was experiencing the same problem while developing for my XPeria 10 mini pro (Android 2.1). The accepted answer of this issue worked for me:
这篇关于Android版的Soundpool有时播放声音时,两次循环参数设置为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!