Different behavior of sounds in Android 4

I have a game in which β€œding” sounds for every point scored in the game. Sometimes you can score points in a very quick sequence. In this case, I do not allow overlapping sounds, so I wait for the mediaplayer isPlaying() function to go false before playing the next sound.

On every phone I have tried so far (admittedly all 2.2 or 2.3), the result is a pleasant sequence of quick-fire sounds.

But now I tried Samsung Galaxy S II with 4.0.3. On this machine, each ding is separated by a long gap. The isPlaying() state seems to last twice as long as the sound itself. According to Audacity, the sound should last about 0.1 seconds, but isPlaying () remains true for .28 seconds.

Sound is saved from Audacity in Ogg Vorbis format.

Any idea what went wrong?

+4
source share
1 answer

It is better to use SoundPool to play quick-fire samples in games, as they are uncompressed once and stored in memory. MediaPlayer can be decoded on the fly, causing a delay as it becomes available. You do not know why there is such a difference between devices, but I would ask SoundPool to try and improve it.

+2
source

Source: https://habr.com/ru/post/1415201/


All Articles