Java – Is it better to choose SoundPool or MediaPlayer in Android?

Is it better to choose SoundPool or MediaPlayer in Android?… here is a solution to the problem.

Is it better to choose SoundPool or MediaPlayer in Android?

I’m currently trying to make an app with buttons to trigger audio files, but these audio files are selected by the user via the file browser activity. I’ve heard that MediaPlayer has latency and other issues, but SoundPool has memory limits?

Also, can I have the user set the audio file by returning a string from the file browser (selected item) and use it for the path to the audio API, whichever it is?

Solution

SoundPool is faster than MediaPlayer, but it has its own limitations.

SoundPool is used for smaller sounds, such as the one you can use in the onClick() method, so that it can make a clicking sound every time the user clicks anywhere, because these files are preloaded into memory and do not affect the CPU, which is what SoundPool is better than MediaPlayer Fast reason. In addition, it can manage the number of audio streams that are rendered at one time.

MediaPlayer is used when the user can access playback options such as play, pause, search, start, and so on. Also, often used for long audio MediaPlayer is good because you can’t load long audio in memory beforehand. You can also use MediaPlayer to play audio over the Internet (useful if you plan to do so in a future release).

In your case, to allow users to play audio from a file browser activity, I recommend using MediaPlayer.

Related Problems and Solutions