Reputation: 23
Sorry for my English. I'm writting android background service app. My app is for electronic voice queue in bank. I need to play audio files one by one in right order. For example I will create a container with audio-files names for example:
string music_names[] = {one.wav, two.wav, three.wav, four.wav, five.wav};
How can I play files from raw directory for example, or from other place? How can I play in right order one by one with delay 1 second?
Upvotes: 0
Views: 583
Reputation: 3873
You have to set an onCompletionListener to each and start the next one on completion.
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
@Override
public void onCompletion(MediaPlayer mp)
{
// Code to start the next audio in the sequence
}
});
The best way to achieve this is to create a class that implements OnCompletionListener which handles the onCompletion and receives the next file to play. This way you can instantiate it nicely in your code. Of course, don't forget your break; in the cases above.
Thanks
Upvotes: 1