tags:

views:

22

answers:

1

I have multiple audio files in the assets directory of my application. When the user clicks a button I want to play those files in a certain order, one after the other. There shouldn't be any noticeable lag between the audio files. What is the best approach to achieve this?

I am thinking of using MediaPlayer objects and OnCompletionListeners. But, that would mean I have to create a lot of OnCompletionListeners because I need to know every time which audio file is next. Am I missing something or is there a better approach?

+1  A: 

you are on the right way, don't need a lot of OnCompletionListener´s.

//define a variable to be used as index.
int audioindex = 0;
//Extract the files into an array
String[] files = null;
files = assetManager.list("audiofiles");

then in your OnCompletionListener.

 mp.setOnCompletionListener(new OnCompletionListener(){
    // @Override
    public void onCompletion(MediaPlayer arg0) {
    // File has ended, play the next one.
   FunctionPlayFile(files[audioindex]);
   audioindex+=1; //increment the index to get the next audiofile
     }
});
Jorgesys