I have received complaints from users of my application that audio
playback will sometimes stop when the screen is blank.  This seems to
be a problem on some phones or Android OS versions, but not everyone
sees this issue.  On checking the documentation I found that the
MediaPlayer by default does not hold a wake lock to prevent the CPU
from being shut down by the power management system while the
MediaPlayer is playing.

I have now added the following call in my application in order to
avoid this problem with the playback stopping:

   MediaPlayer.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK);

Now that my application is holding a PARTIAL_WAKE_LOCK, my concern is
what will happen if the battery runs low?  I started to code a
BroadcastReceiver for ACTION_BATTERY_LOW in order to release the wake
lock and make sure that the player would stop if the battery is low.
However when I looked for the correct parameter to pass to the
MediaPlayer.setWakeMode() to restore the original behavior (no wake
lock) I couldn't find any value to do this.

The documented wake lock mode parameters (in order of increasing power
consumption) are:
   PARTIAL_WAKE_LOCK
   SCREEN_DIM_WAKE_LOCK
   SCREEN_BRIGHT_WAKE_LOCK
   FULL_WAKE_LOCK

There is no documented value to pass to MediaPlayer.setWakeMode() in
order to tell it to stop holding the PARTIAL_WAKE_LOCK

There isn't any documentation to indicate if the MediaPlayer is
already listening for the ACTION_BATTERY_LOW broadcast itself and
taking appropriate action, so I really don't have to worry about
this.  There isn't any documentation to tell me how to tell the
MediaPlayer that it is OK to let the CPU shut down when the battery is
low.

I would like my application to be a "good power citizen" and would
appreciate any help and direction on the correct way to implement
this.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to