How to create and play a sound or audio queue in Android
android, audio
Solution
There are two ways I can see this working: using a `MediaPlayer` or a `SoundPool`
MediaPlayer
You can use MediaPlayer.OnCompletionListener combined with a list of files to simply listen for completion and play the next one. By and large this works quite well and I have used it to play sequences of very short clips (< 1s) without problems.
SoundPool
Another way is to use the SoundPool class combined with a handler to simply queue up play events in advance. This assumes you know the length of each clip but depending on the format you should be able to find this out.
Which solution you choose depends on a number of factors: how many files, how short they are, what format they are in, where you are getting them from, how fixed or variable the list is, etc.
Personally I would go with `MediaPlayer` as this is easier to implement and would probably fit your needs.
Problem
I have many short audio fragments which should be played sequentially with minimum latency. How can I queue these sounds efficiently?