Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7162613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:45:52+00:00 2026-05-28T13:45:52+00:00

I have a media player that stops playing whenever the user closes the app,

  • 0

I have a media player that stops playing whenever the user closes the app, either by pressing the home button, using the back button or simply opening another app.
To get this behavior, I added an onStop() to my main activity which tells my MediaPlayer(which is in a service) to stop playing music.

However, I would like the music to keep playing whenever the screen gets dimmed, either by using the power button to turn the screen off, or just by the screen auto dimming.

Right now the player also stops playing when the screen dims, meaning that the onStop() method also gets called then.

How can I check if the onStop() gets called by the screen diming?

I already applied a PARTIAL_WAKELOCK to my MediaPlayer object, which to the best of my knowledge, should make it possible for the player to keep running after the screen goes off.

Do I need to add a partial wakelock to my main activity as well?


Just applied a PARTIAL_WAKELOCK to both my main activity, as well as my media player.
Right now, the screen doesn’t turn off by itself anymore, and when the user presses the power button the music still stops.

Obviously, this doesn’t work as I thought it does.

Is there any way of achieving the behavior I’m looking for?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:45:53+00:00Added an answer on May 28, 2026 at 1:45 pm

    You can add

    private boolean stoppedByUser = false;
    

    field to your activity, set it to false in onStart(), to true in onBackPressed() and onUserLeaveHint() and check it’s value in onStop() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C# app, and I'm looking at using the Windows Media Player
I'm using Windows Media Player in a web page. I have version 11 installed
I'm currently have a media player that is streaming an mp3 file. When that
I have an activity that is a service which plays audio using a media
I have some Windows Phone 7 code that starts playing a sound using SoundEffect.FromStream.
I have a simple ASP.NET page that uses the VLC media player to play
i have windows media player in my application.i want to allow only the supported
I would like to implement the following behaviour: I have a special media player,
I have HTML page where windows media player is embedded. It works very well
We have a site hosted in IIS6 that we built using the .NET 1.1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.