StackOverflowed
StackOverflowed

Reputation: 5975

Android MediaPlayer - sleeping behaviour

I have an app that plays audio streamed from a server (or locally).

According to what we've seen*, if playing audio through a background Service, the audio will keep playing. However, some users report that the audio will stop when their device goes to sleep. I haven't seen any documentation on audio behaviour while sleeping, definitely the API docs don't mention anything: http://developer.android.com/reference/android/media/MediaPlayer.html . Are there any guarantees that the MediaPlayer will continue playing while sleeping, and if not, should I enable the WAKE_LOCK while playing?

*(and this question seems to support it: Playing music in sleep/standby mode in Android 2.3.3)

Upvotes: 2

Views: 1248

Answers (2)

Dororo
Dororo

Reputation: 3440

If you app goes into the background, it can be killed by the OS. This is most likely what is happening. You can reduce the chance of this happening greatly by making your Service a foreground service by using startForeground(). A wake lock will not help. Under intense memory strain, your foreground service may be killed, but this is very unlikely when the phone is asleep.

Upvotes: 1

William Seemann
William Seemann

Reputation: 3530

I don't think setting the wake lock will matter, in my experience it has nothing to do with keeping a service alive. The Android Service documentation states that services that don't use the startForground() method can be killed to free up memory. It's likely the service is either being killed to free up resources or an exception is causing it to silently crash.

Upvotes: 1

Related Questions