Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does my SoundPool sound not play the first time on Android?
    primarykey
    data
    text
    <p>I've got a got a curious problem with playing Ogg Vorbis sounds on Android that I'm having difficulty correcting. I'm using the SoundPool class to play sounds. It works great with the exception of the first sound that I play after a pause. </p> <p>Here's the issue I'm encountering: I have a menu with several buttons on it. If I hit a button, I play a tick sound. However, the very first time that I attempt to play one, it does not emit a sound. Then, if I hit the same menu button again, it works. If I then delay the next press for several seconds, the issue re-appears. Specifically, I see the following behavior:</p> <ul> <li>wait several seconds</li> <li>touch UI button which should emit a sound ... it doesn't</li> <li>log cat reports "AudioFlinger: write blocked for 165 msecs, 66 delayed writes, thread 0xec40" (happens immediately when I touch the UI button)</li> <li>wait several seconds</li> <li>log cat reports "AudioHardwareQSD: AudioHardware pcm playback is going to standby"</li> <li>touch UI button which should emit a sound... it doesn't.</li> <li>logcat reports "AudioFlinger: write blocked for 166 msecs, 67 delayed writes, thread 0xec40" (happens immediately when I touch the UI button)</li> <li>touch UI button again, but <em>before</em> AudioHardwareQSD standby message appears... SOUND WORKS!</li> </ul> <p>I've seen this behavior on a few different devices: HTC Incredible, rooted Nook Color, and HTC Thunderbolt, so I don't believe it is device specific.</p> <p>I'm GUESSING this is a function of the AudioHardwareQSD going to standby. Once it is in standby, the first sound out of the chute gets ignored, while subsequent sounds work until it hits standby once again. There is roughly a 3 second delay between the 'write blocked' message and the AudioHardwareQSD message on my HTC Incredible.</p> <p>There's an answer on StackOverflow here that discusses using WakeLock to prevent this from happening. I tried that solution and it did not fix my problem.</p> <p>Why is this happening? Is there a way to prevent AudioHardwareQSD from going into standby? Does anybody have any tips on troubleshooting this?</p> <p>Thanks!</p> <p>UPDATE: I've been able to implement a rather crude workaround that corrects this problem. In my application (a game), I have a sounder rendering class. I added a new method present() that is executed by the game logic on a periodic basis. The method uses a 1.5s timeout timer. When the timer bottoms out, the sound renderer plays an audio file that consists of 50ms of silence and then resets the timer. </p> <p>This has corrected my issue... Far from optimal, but it works.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload