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?.
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.
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.