Prevent Doze for audio streaming

A small extension to prevent Doze mode during playback of an audio stream.

grafik

Example blocks using AudioExoPlayer extension by @Patryk_F:

Even streaming URLs that do not work with the MediaPlayer (player component or MediaPlayer-based extensions) work perfectly with these extensions.

5 Likes

This extension can also keep other components awake, such as sensors like the Pedometer and/or a Timer. However, you may need to justify if you want to publish your app in the Play Store why you declared foregroundServiceType="mediaPlayback".

For this you could for example, loop a silent 5-second audio file (or a non-silent sound that is inaudible to humans) using the Player component and trigger this loop simultaneously with the Pedometer or Timer. It will certainly not be possible to analyze the silent.mp3 file via the Pre-launch report. Whether Google still has objections to this is another question.