Android soundpool timing

Is there a reliable way to prevent truncation of sounds in soundpool? I had some success in the sleep () function between sounds, but they still sometimes skip the last bit of sound before starting another sound. My application plays short sounds in sequence. Jerry

+3
source share
2 answers

Although this is an old question, it seemed to me that I would post something here, since I could not find a solution to this problem on the Internet, but came up with something like a solution ...

I get the duration of each sound (using MediaPlayer) when the application starts and save the value of R.id.sound_name and duration together. Then I can play sounds using SoundPool.

Code for getting duration:

private long getSoundDuration(int rawId){
  MediaPlayer player = MediaPlayer.create(context, rawId);
  int duration = player.getDuration();
  return duration;
}

In my sound class, I play the sound as usual, and then sleep for a while. Pretty simple stuff.

Seems to work well. Gives me the benefits of low latency from SoundPool, plus the ability to cling to things.

A few notes:

  • Do not get a duration every time since creating MediaPlayer has overhead.
  • Durations come from file metadata - ogg works great for me, but I can't vouch for anything else.
+5
source

, . SoundPool MaxStreams. , . 8 , ... , .

+3

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


All Articles