ExoPlayer stutters / stops after screen turns off or in background

I’ve found a solution to this issue:

You need a Foreground service to keep the WiFi / Network connection alive and don’t fall into Doze mode.

Try this APK and test it with and without Foreground service:

  • don’t charge the device while testing
  • start the app, click play and press the power button to put the device in the background (idle mode, screen off).
  • without Foreground service the sound will stutter / stop after ~ 1-10 min
  • with Foreground service the sound (looped) will play forever … :slightly_smiling_face:

Check playing

  • from assets and
  • from URL (streaming).

See also here:

→ Doze mode

Doze mode https://hashedin.com/blog/save-your-android-service-from-doze-mode/
“Doze mode is exactly like its name suggests. If the user leaves the device unplugged for a period of time and the screen is off, then the device will enter into Doze Mode. In Doze mode, the system attempts to conserve battery by restricting apps from accessing the network and intensive CPU utilization services. It also prevents the app from accessing the networks and defer their jobs, syncs, and alarms."

5 Likes