Skip to content

Context.startForegroundService() did not then call Service.startForeground() #2459

@Woffkaa

Description

@Woffkaa

Version

Media3 1.6.1

More version details

ANDROID_BUILD_SDK_VERSION = 35
ANDROID_BUILD_MIN_SDK_VERSION = 21
ANDROID_BUILD_TARGET_SDK_VERSION = ANDROID_BUILD_SDK_VERSION

JAVA_VERSION = JavaVersion.VERSION_17
KOTLIN_JDK = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.20"

GRADLE_PLUGIN_VERSION = "8.6.0"
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip

ANDROIDX_APPCOMPAT = "androidx.appcompat:appcompat:1.7.0"
ANDROIDX_MEDIA3_VERSION = "1.6.1"
ANDROIDX_MEDIA3_SESSION = "androidx.media3:media3-session:$ANDROIDX_MEDIA3_VERSION"
ANDROIDX_MEDIA3_EXOPLAYER = "androidx.media3:media3-exoplayer:$ANDROIDX_MEDIA3_VERSION

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <!-- MusicService -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" /> <!-- MusicService -->

<service
    android:name=".services.music.MusicService"
    android:exported="true"
    android:foregroundServiceType="mediaPlayback">
    <intent-filter>
        <action android:name="androidx.media3.session.MediaLibraryService" />
        <action android:name="android.media.browse.MediaBrowserService" />
    </intent-filter>
</service>

Devices that reproduce the issue

3100 crashes affecting 310 users on Android 11 (Only Samsungs, Only Galaxy A** series, not S**)

1200 crashes affecting 300 users on Android 11 (96%), Android 10 (2%), Android 9 (1%) and Android 8 (1%).
71% Samsung (All Galaxy series, A** and S**), 24% Xiaomi (Redmi, Mi, Xiaomi)

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

No

Reproduction steps

I have no idea
I spent hours trying to reproduce the crash when the app is in the background or removed from recents, and also using bluetooth headphones. Never worked.

I do NOT use the PlaybackResumption feature (#167)
and I do NOT see any ForegroundServiceDidNotStartInTimeException.

I do NOT override any of
onGetChildren
onGetItem
onGetLibraryRoot
onGetSearchResult
onAddMediaItems
onSearch
onSetMediaItems

But I see a lot of
Context.startForegroundService() did not then call Service.startForeground()
crashes (99% of all crashes)

The service only plays radio or a list of podcasts.

Here is a gists
How I manage the MediaBrowser lifecycle
https://gist.github.com/Woffkaa/15cc3565a82366a49d009a4b0ea6b42b
How I start the playback
https://gist.github.com/Woffkaa/11e2d11458f55122d963e9e508495feb
And the service itself
https://gist.github.com/Woffkaa/966c2ead021a3dced1f105e1f6c6480b

Expected result

No crash?

Actual result

A lot of crashes on Android 11

Is it my fault or are we still waiting for someone to reproduce and describe the steps in the demo?

Image

Image

Media

.

Bug Report

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions