Playing audio files one after another

后端 未结 7 1309
情书的邮戳
情书的邮戳 2020-12-10 06:05

I have a list of audio files like this,

int music_numbers[] = { R.raw.one, R.raw.two, R.raw.three, R.raw.four,
            R.raw.five, R.raw.six, R.raw.seve         


        
7条回答
  •  不思量自难忘°
    2020-12-10 06:56

    You need to set an onCompletionListener to each and start the next one on completion.

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

提交回复
热议问题