Mediaplayer Stop Playing After About 5 Seconds

android media player stops playing after some minutes

ok, so i finally solved the problem. Incase any one else run into this issue

in onCreate i checked if the video was already playing, to make sure it isn't called to re-play each time.

int firstPlayed = 0;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mp = MediaPlayer.create(this, R.raw.my_webm_video);
mp.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
if(!mp.isPlaying()) {
firstPlayed = 1;
playVideo();
}
}

I checked in onResume incase the user navigates out of the activity and goes back, Which makes the video screen turn black.

public void onResume() {
super.onResume();
if(!mp.isPlaying() && firstPlayed == 0) {
mp = MediaPlayer.create(this, R.raw.my_webm_video);
mp.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
playVideo();
}
firstPlayed = 0;
}

And then i noticed that i needed a firstPlayed check to be sure.

Mediaplayer stops after 5 seconds on new Activity

I believe you're MediaPlayer from Activity 1 is being wiped from memory since you're calling finish(). The MediaPlayer instance is part of the first Activity. The only way to fix this is to start a new MediaPlayer in your Activity 2 or create a Service that handles all media in the background. If you do it the second way, the one MediaPlayer instance will remain playing through all your activities and you only need to send commands to it.

Mediaplayer Stops playing

Look at this one it is the same case for you.

Link

but i think it is something else at your case.



Related Topics



Leave a reply



Submit