4

I am currently trying to make an app where there are buttons that trigger audio files, but these audio files are selected by the user, via a file browser activity. I have heard that MediaPlayer has latency issues and such, but SoundPool has memory limitations?

Also, can I let the user set the audio file by returning a string from the File Browser(selected item) and use it for the path of the audio API, which ever one it is?.

  • Possible duplicate of [AudioTrack, SoundPool or MediaPlayer Which Should I use?](http://stackoverflow.com/questions/13527134/audiotrack-soundpool-or-mediaplayer-which-should-i-use) – payam_sbr Nov 28 '16 at 03:48

2 Answers2

4

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

SoundPool is used for small sounds like the ones that you can use in your onClick() method so that it can make a click sound every time user click anywhere because these files are pre-loaded in the memory which doesn't let the CPU suffer for its deeds and that is why SoundPool is faster than MediaPlayer. Also, it can manage the number of audio streams rendered at once.

MediaPlayer is used for such cases in which user have access to the playback options like play, pause, seek, start etc. Also, commonly for long length audio MediaPlayer is good as you cannot load long length audio in the memory beforehand. You can also use MediaPlayer to play the audio over internet (it would be useful if you are planning to do it for future release).

And in your case user is allowed to play audio from a file browser activity, I suggest you go for MediaPlayer.

hittsss
  • 76
  • 5
3

SoundPool is faster if you are trying to play already loaded files. as it takes lil more time to load files and file should be smaller for better performance.

But in your case it seems user chooses files to play from FileBrowser, and file size will differ, so the loading time. Go for MediaPlayer instead.

AAnkit
  • 27,299
  • 12
  • 60
  • 71
  • That is my understanding as well, `SoundPool` is really for things like games where you can store many sound effects compressed in the apk but not have to deal with delay decompressing after loading. `SoundPool` also gives you the ability to change to rate of play which is nice for sound effects. – draksia Feb 14 '13 at 20:03
  • 1
    yeah, and better thing with soundPool is you can load sounds at once dont need to load everytime you gonna play. MediaPlayer is just opposite. And in OP's case MediaPlayer is perfect. – AAnkit Feb 14 '13 at 20:10
  • What about issues with MediaPlayer lag between button presses and the actual playing of the file? – Naail Kashif-Khan Feb 14 '13 at 20:28
  • This will always happen, since the stream needs to be loaded even if it is local. You should make a ui progress spinner to let the user know it is loading and add a `OnPreparedListener` to your `MediaPlayer` and when it is called remove the progress spinner. – draksia Feb 19 '13 at 20:29