Setting an array of songs using MediaPlayer

前端 未结 3 1190
离开以前
离开以前 2021-02-10 16:43

I have 5 songs which i need to play one after the other, and it must loop from the first song after finishing the 5th song. How do I use the MediaPlayer to achieve this?

3条回答
  •  难免孤独
    2021-02-10 17:00

    you need to use CountDownTimer for this. CountDown timer has give you facility to do this one by one ::

    MediaPlayer mp_xmPlayer2  = new MediaPlayer();
    mp_xmPlayer2 = MediaPlayer.create(this, R.raw.bg_music_wav);   
    
    
     for(int i=0;i<5;i++)
        {
        CountDownTimer cntr_aCounter = new CountDownTimer(3000, 1000) {
            public void onTick(long millisUntilFinished) {
    
                mp_xmPlayer2.start();
            }
    
            public void onFinish() {
                //change music name
              }
            };
            cntr_aCounter.start();
        }
    

提交回复
热议问题