ExoPlayer stutters / stops after screen turns off or in background

Not for a live stream just looping to a static sound .mp3

Works on stream too
MusicPlayer.apk (5.9 MB)

1 Like

Yes, exactly.

1 Like

That is generated by myself
https://atomdeveloper.com/manifestgenerator.html

1 Like

Yes, sorry

And obviously this does not have to be declared in the Manifest, since it is true by default:

service android:enabled="true"

Hmm @bodymindpower did you try to run app in background if yes then pls tell me also. I can added code to manifest using atom Developer extension and how did you run the code to perform background services ???

This is about a Foreground service (and not a Background service) to prevent Doze mode (and thus the stuttering / stopping of the sound in idle (sleep) mode).

1 Like

Thanks its work. But if i press backpress it will close app and stop the music.

Yes, of course, because the app is closed then and as I said:

2 Likes

thank you for clearing that up, much appreciated and embraced :slight_smile:

This one work very well on new Android versions when Doze mode exist(API >= 23), except when call Start function block got error
Screenshot_20210124-112552
on my phone Blackberry ZTE Android 6.0.1 (API 23).

It’s look like the code do not check if some fonctions are supported…

I used another app to test if the phone support Doze mode and i discover it does not support it.
So it’s mean i can not based on API version to check if the phone support it.

Do someone know how to check if Doze mode supported?

And then how to avoid sleep on old devices who do not support Doze mode?
I Set “Keep WiFi on during sleep” to “Always” and disable Battery Optimisation manually, but the internet still sleep when playing audio with Exo player.
But this happen only if playing playlist with multiple short audio, when playing a long one this do not happen.

1 Like

A post was split to a new topic: Simple Doze Mode Extension to find out, if Doze Mode is supported

https://developer.android.com/reference/android/content/Context.html#startForegroundService(android.content.Intent)

1 Like

Btw, the presence of Doze does NOT automatically imply that WLAN etc. are throttled / switched off in the background (idle mode); it seems to be manufacturer-dependent in this respect (Samsung is apparently primarily affected).

1 Like

You can actually change the UI. :wink:

@bodymindpower Is there any method now to play music in background?

It depends on what you mean by “background”. This is how it works when the screen is in the background (not visible) or when the device is in idle (sleep) mode. If the music should also be played when the app has been closed, a background task must also be started / used. A background task alone is not sufficient for this, as it does not prevent Doze mode from being activated (on some devices). A foreground service is also required for this to ensure that Doze mode is not activated.

@bodymindpower Ok.
What I understood is exoplayer can run in the background even when an app is closed by using the foreground service which can also be achieved using @Atom_Developer 's foreground task extension.
But I want the exoplayer to run till the app is in recent. The app is not closed and it’s in the recent tab. I can listen to the audio of the application in the application and run other application too. Do i have to give any special permissions or?

As I have already said often enough, if the app is not closed, but only the screen is not visible, no background service is required, just a foreground service so that the music also plays in the background (i.e. when the screen is not visible) .

1 Like