Skip to content

Fix background audio stopping after notification

When playing a podcast in the background, receiving a notification will trigger a pause of the playback, for the notification to pass, then will resume playback and seek backwards so the user doesn't miss any audio.

In the delayedPodcastRunnable of VLCAudioFocusHelper, resumePlayback() and service.seek(position, fromUser = true) are called in sequence. Both trigger a showNotification, resumePlayback through the libvlc event Playing, seek right in it's function.

Problem is, seek will trigger the showNotification before the event Playing happens. showNotificationInternal of PlaybackService will call stopForeground when called while playback is stopped. Then showNotification called from playback resuming will try to startForeground to ensure the service isn't killed by the system, which is not allowed as startForeground can only be called with the app in the foreground or through user inputs like the notification buttons, see https://developer.android.com/develop/background-work/services/fgs/restrictions-bg-start.

To avoid calling stopForeground, seek should not be called from VLCAudioFocusHelper with the fromUser parameter true, though we do need to updateState should still be called to update the auto ui.

Fixes #3218

Edited by Duncan McNamara

Merge request reports

Loading