Android SoundPool sometimes plays sound twice when loop parameter is set to 0

That's what I'm doing:

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(); } 

Initially, I used a WAV file for a click sound, and the problem would have occurred in 90% of cases. I added setLoop and it seems to have reduced it a bit.

I thought it might be a problem downloading .wav files, so I converted the file to .mp3. Now the problem occurs in 5% of cases, but it still occurs. I built with and without calling setLoop, and it seems that including it helps a bit.

As you can see, I added a debug log message to make sure that I don't accidentally call the play function twice. According to the log output, the sound is played only once, but I hear the sound twice.

I also used several different sound files. Some of the files seem to be repeated more often than others. I see no correlation, except when it happens more often with .wav files.

I see that the problem on Samsung Continuum is running 2.1 (minimum and target API: level 7). I did not have any additional cycle with any applications on the market that I downloaded on one device. Unfortunately, I do not have other devices for testing.

I just found another person experiencing this problem, and he or she also used a Samsung device.

Here is a link to another problem:

https://stackoverflow.com/q/4873995/695336

At this point, I think I’ll try to build the releases to see if this is all happening and then maybe convert to .ogg format. After that, I will probably try switching to MediaPlayer to see if I get the same results.

Thanks for your help.

+1
android audio
Apr 6 2018-11-18T00:
source share
1 answer

I had the same issue when developing for my XPeria 10 mini pro (Android 2.1). The accepted answer of this question worked for me:

Problem with Soundpool and Samsung Galaxy S

+2
Apr 10 2018-11-11T00:
source share



All Articles