ExoPlayer stutters / stops after screen turns off or in background

I have built a simple app to play (looping) a sound (loop.ogg, 22 sec) from the assets. But if some devices (e.g. Samsung Galaxy S8, Note8, Android 9) go to background (pressing the Home button) or I turn the screen of (standby, sleep mode), the sound begins to stutter after about 50-60 sec and later it stops.
ExoPlayer_test.aia (466.8 KB)
This does not happen on my Xiaomi Redmi Note 5 (Android 9), OnePlus 6 (Android 10).

We already discussed a similar issue (bug) in the forum, but without any result. Exoplayer about 10 or 15 minutes the application closes when the screen turns off

If this issue (bug) cannot be solved, the ExoPlayer is practically useless.

Can you please answer this question @Kodular :
Is there still a (real) chance / perspective for ExoPlayer in the near future regarding this problem?

If not, that would be the time for the @ExtensionDevelopers to consider whether to create an extension for playing and gapless looping sounds / audio files (without these issues in standby / background).

Almost every music / sound app that works with background music / sounds needs this ability.

Note:
The TaifunPlayer extension is working in standby / background and has the ability for seamless looping, but unfortunately gapless looping doesn’t work on some specific Chinese devices (e.g. Xiaomi Note5, OnePlus 6) any more.

6 Likes

DeepHost has a music player extension that I purchased last year. I had stopped working with it because the UI background can’t be changed since it’s fixed in white colour and I wanted to make a dark mode application. However, I can say that it loads online music as fast as ExoPlayer.

Later I will be doing some tests with it.

Yes, thanks, I know, but as far as I can see there is no looping feature.

2 Likes

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 How To 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

Really good job @bodymindpower!!

I just tested and it really works:
From URL.
Without Foreground service: 4:30
With Foreground service: I don’t know because it still playing (I think it won’t stop).

How did you integrate Foreground service?

1 Like

As I said it will play forever (because it is looped):

Note:
The TaifunBatteryOptimization.Request definitely doesn’t solve the Doze problem as is often claimed. See e.g. here:

I’ve tested this extensively on dozen of devices.

1 Like

May we know how we can integrate it? :sweat_smile:
I guess by extension…

Yes, you need an extension. And unfortunately you have to edit the Manifest manually after compiling and make an additional entry there. I’ll keep working on it as soon as I have more time.

2 Likes

Would you please provide the solution, what’s changes we will have to make …
A video tutorial is appreciated.
Thanks

Looking forward for your findings

Hello bodymindpower, did you found time to make the extension in order to use Foreground service?

By the way i like the looped sound, it make me sleep… :sleeping:

So I am going to edit the manifest file in Android Studio or is there a easier quicker way?

APK Editor Studio

https://qwertycube.com/apk-editor-studio/

1 Like

You can use al2alive extension by ullis reboter ,
https://ullisroboterseite.de/android-AI2-KeepAlive-en.html

Service manifest by manifest generator by atom developer
com.atomdeveloper.ManifestCode.aix (6.0 KB)

And its perfectly works in kodular too ,
test aia : MusicPlayer.aia (4.5 MB)

3 Likes

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"