Roberto
Roberto

Reputation: 528

MediaPlayer stopping when starting another activity


I have a problem with the MediaPlayer.
I have a MediaPlayer class that starts as soon as the user launches the App, but as soon as the user taps on the "credits" button another activity starts with the credits screen, but the MediaPlayer stops playing the audio stream.

Is there a way to avoid this?

MediaPlayer setup:

player = new MediaPlayer();
player.prepareAsync();
player.setOnPreparedListener(new OnPreparedListener() {

    public void onPrepared(MediaPlayer mp) {
        player.start();
    }
});

I change page with this:

Intent intent = new Intent(this, Credits.class);
startActivity(intent);

Upvotes: 1

Views: 646

Answers (2)

Dave
Dave

Reputation: 4291

Create a local service and put the MediaPlayer in that Service. Bind to the Service from whatever Activity needs to control the MediaPlayer.

Upvotes: 1

Robin Dijkhof
Robin Dijkhof

Reputation: 19278

This is not possible since the mediaActivity will be pause. You might consider using a dialog instead of an intent for the credits.

Upvotes: 0

Related Questions