How to play audio files one after the other

前端 未结 3 604
悲&欢浪女
悲&欢浪女 2020-12-10 20:33

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. Ther

3条回答
  •  [愿得一人]
    2020-12-10 21:24

    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
         }
    });
    

提交回复
热议问题