I'm trying to use media3 and for that I'm following the tutorial here: https://developer.android.com/guide/topics/media/media3/getting-started/playing-in-background
However when I run my code I have the following error on this line:
val sessionToken = SessionToken(this, ComponentName(this, PlaybackService::class.java))
java.lang.IllegalArgumentException: Failed to resolve SessionToken for ComponentInfo{com.example.euphonia/PlaybackService}. Manifest doesn't declare one of either MediaSessionService, MediaLibraryService, MediaBrowserService or MediaBrowserServiceCompat. Use service's full name.
Things are already properly declared in my manifest as shown in my tutorial
<service
android:name="PlaybackService"
android:foregroundServiceType="mediaPlayback"
android:exported="true">
<intent-filter>
<action android:name="androidx.media3.session.MediaSessionService"/>
</intent-filter>
</service>
How can I solve this issue?
I've reproduced this runtime error and it seems like your service declaration is the culprit: if your PlaybackService
class is in a package (from the error it seems like it is) your service declaration should take that into consideration:
<service
android:name=".PlaybackService"
...
or using its fully qualified name
<service
android:name="com.example.euphonia.PlaybackService"
...