If my activity is running in the foreground and the display is turned off and then turned back on again the background music starts to play again before the screen is unlocked. The background music is paused in onPause() and continues to play in onResume(). So when the app is pushed to the background the music stops.
Is there a way to prevent the music from playing while the lock screen is on?
//André
Take a look over here.This will solve your problem.
https://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/
Related
I'm using the AlarmManager for playing a sound (with MediaPlayer) at a given time.
Unfortunately the play() method doesn't seem to work when the phone is locked.
I'm developing on Marshmallow, so I already solved the Doze issues by using setAlarmClock() and using a CPU wake lock (the Partial wake lock). The strange thing is that the activity launches over the lockscreen (what it should do) when the alarm fires, but the play() method of the MediaPlayer doesn't play.
When I rotate the screen, the music starts playing.
How can I solve this, so the music start playing when the activity is launched, altough the phone is locked?
Because of the Dose Mode. When you rotate a screen Dose mode is disabled. Try to add your app in white list
I have implemented a media player in a service and it works fine when i have a playlist is on as long as the screen is on. However, when the screen is locked, playback stops after a couple of songs and i have to press play again in order to continue.
Is there anything that causes the service to stop or the media player to pause playback when the screen is off, even after I add a partial wake lock?
In Android development, is it possible to keep a VideoView playing after sending the user to HOME screen, so, when the user opens the Application once again, the video is already running?
Like, when I leave the activity, the video stops playing and when I go back to the same Activity, the video restarts. Is there some way to keep it running, like in the background?
Thank you!
In your onPause() of the activity you can pause the video get the current seekLevel by getCurrentPosition() and in your on resume if the video was playting you can pick up where you left of
I have developed a music player application,which has a service(AudioPlayerService) which will be running in the background.Service will be started when play button is pressed. It will run in the background even though application goes to background.
Playback can be stopped by bringing the app to foreground and press the stop button, which makes the music to stop and stops the AudioPlayerService too. everything works fine.
Otherway i can use the Force Stop from Settings app (Settions->Application->Downloaded->Select the App->Press Force Stop Button).
I am able to stop the application and music also stopped playing.
But If i use Stop button from Settings App (Settings->Applications->Running->Select the App -> Press Stop), application is terminated and my app is removed from the running app list, but music is still playing in the background.
I am not sure why Running Tab Stop Button does not stop the music.
Any one help me if i need to handle anything in my service to class to stop the playback.
I am testing in Samsung Galaxy S2 with Android 4.0.3
Thanks
Sasikumar JP
On the onDestroy override method of your service use your mediaplayer object to stop the media from playing.
#Override
OnDestroy{
mediaplyer.stop();
}
I have a MediaPlayer that keeps playing when I change activities and when I even click the physical Home button on my phone. How can I make it so that the MediaPlayer keeps playing when I change activities yet stops playing when I click the Home screen button?
You can use a service. that keeps running the background.
the service is similar to normal activities but they run in background and dont have a user interface