How do you detect when a sound file has finished?

前端 未结 3 1326
面向向阳花
面向向阳花 2020-12-05 17:18

I am playing a sound file using this code inside a broadcast receiver activity:

notification.sound = Uri.parse(\"android.resource://emad.app/raw/seven_chimes         


        
3条回答
  •  不知归路
    2020-12-05 17:38

    You can use the MediaPlayer class and add a Completion listener to be activated when the sound finishes playing

    MediaPlayer mp = MediaPlayer.create(this,Uri.parse("android.resource://emad.app/raw/seven_chimes"));
    
    mp.setOnCompletionListener(new OnCompletionListener() {
    
        @Override
        public void onCompletion(MediaPlayer mp) {
            performOnEnd();
        }
    
    });
    
    mp.start();
    

提交回复
热议问题