TiagoM
TiagoM

Reputation: 3526

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 ;)

Upvotes: 1

Views: 622

Answers (1)

Sam
Sam

Reputation: 1662

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

Upvotes: 2

Related Questions