Luis A. Florit
Luis A. Florit

Reputation: 2599

PARTIAL_WAKE_LOCK kills my mediaplayer

I implemented a wakelock to avoid stopping my MediaPlayer (playing local files only) when screen goes off. Since I don't want to drain battery, I tried a PARTIAL_WAKE_LOCK. But it has no effect: screen off kills my player. FULL_WAKE_LOCK works fine, but screen stays on, as expected, draining the battery...

What am I doing wrong?

Thanks! L.

Upvotes: 0

Views: 1176

Answers (2)

S.Mani
S.Mani

Reputation: 31

It looks like you are using the wake lock for the wrong purpose. From what I understood based on your explanation: you need the playback to continue when the screen goes off:

To do that - I would recommend you try the following logic.

  • Try to have the player running in a service (not in the activity)
  • Start the service with startForeground method (this will need you to include a notification as well)
  • Use a Messenger to communicate between your activity and service.

But the wake lock may come handy; as this may be helpful in handling a audio stutter issue in future. I am not very sure about this part as I myself is yet to try out the wake lock as a solution to stuttering issue.

(I am not a professional/commercial programmer ; rather an ad-hoc developer who finds a requirement designs a solution, develops it and uses it for myself. So my solution might not be a 100% professional approach but I am sure it does the job)

Good Luck and happy coding - S.Mani

Upvotes: 3

NikkyD
NikkyD

Reputation: 2284

Wake Lock is to make sure the device does NOT go into standby.

What you want is to listen for Intent.ACTION_SCREEN_OFF that tells you that the screen is now off

Upvotes: -1

Related Questions