简体   繁体   中英

Android MediaPlayer Handler for when Music Stops

I need to know when the MediaPlayer stops playing the music I request, so I can invoke a new Activity to Start.

In my application, I have buttons that Speak when I click them, but I want to listen the entire audio and only after I invoke the start of the next activity.

I am doing this way now:

        MediaPlayer mPlayer = MediaPlayer.create(this, R.raw.h);
        mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mPlayer.start();
        Intent intent = new Intent(this, DrawActivity.class);
        startActivity(intent);

But the music doesn't even start, I want the new Intent to start only when I the music stops. I know that I can make a postDelayed Runnable to launch the activity, but I would not know the exact time, only a guess...

Is there a way to attach an Event Handler to the MediaPlayer to when the music ends, it invokes the method associated to the Event Handler?

That would be amazing.

Thanks alot for your help anyway ;)

Check this callback . But this is called when end of playback source was reached. Also You can check other callbacks there

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM