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
How to Set Camera Image Orientation
How to Create Ripple Effect in Simple Layout
JSONarray Cannot Be Converted to JSONobject Error
Is Fcm (Firebase Cloud Messaging) Token for One Device or for One Account
Background-Attachment: Fixed Interfering with Background-Size
Firebase Endat() Not Working with Date String
How to Access Files Under Assets Folder of Other APK'S
When Should I Recycle a Bitmap Using Lrucache
Android 4.3 and Phonegap, Cant Tap Link
Display the App Icon If the Contact Is Associated with the Application in Phone Address Book
Gradle Dsl Method Not Found: 'Implementation()'
Intent Filter to Download Attachment from Gmail Apps on Android
How to Embed a Youtube Clip in a Webview on Android
Android Imageview Change Tint to Simulate Button Click