MediaPlayer play audio in background and play next one

前端 未结 2 1471
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-14 01:45

I use below code to play audio in background:

String[] Path = new String[] {path1, path2, ...};
mMediaPlayer.setDataSource(Path[i]);
mMediaPlayer.prepare();
         


        
2条回答
  •  遥遥无期
    2021-01-14 02:01

    You should override onCompletionListener like this,

    mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {           
        public void onCompletion(MediaPlayer mp) {          
            Log.i("Completion Listener","Song Complete");
            mp.stop();
            mp.reset();
            mp.setDataSource([nextElement]);
            mp.prepare();
            mp.start();
        }
    });
    

    If you use a onPreparedListener in your MediaPlayer then you cal also use the prepareAsync command and ignore the .start().

提交回复
热议问题