media
media copied to clipboard
how to dot not cancel notification when player is paused and you close the app?
when i press pause and close the app, notification Invisible how to dot not cancel notification in code in this situation.
my code:
class ExampleLibraryPlaybackService : MediaLibraryService() {
private var exoPlayer: ExoPlayer? = null
private var mediaSession: MediaLibrarySession? = null
@OptIn(DelicateCoroutinesApi::class)
override fun onCreate() {
super.onCreate()
setMediaNotificationProvider(ExampleMediaNotificationProvider(this))
val exoPlayerBuilder = ExoPlayer.Builder(this)
exoPlayer = exoPlayerBuilder.build()
val commandButtonExtras = Bundle()
commandButtonExtras.putInt(
DefaultMediaNotificationProvider.COMMAND_KEY_COMPACT_VIEW_INDEX,
0
)
val sessionCommand = SessionCommand(SAVE_TO_FAVORITES, Bundle.EMPTY)
val favoriteButton =
CommandButton.Builder()
.setEnabled(true)
.setDisplayName("favorites")
.setExtras(commandButtonExtras)
.setIconResId(R.drawable.favorite)
.setSessionCommand(sessionCommand)
.build()
val intent = packageManager.getLaunchIntentForPackage(packageName)
intent?.putExtra("DESTINATION", "player")
val pendingIntent = PendingIntent.getActivity(this, 0, intent, FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT)
mediaSession =
MediaLibrarySession.Builder(
this,
exoPlayer!!,
object : MediaLibrarySession.Callback {
//......
})
.setCustomLayout(ImmutableList.of(favoriteButton))
.setSessionActivity(pendingIntent)
.build()
}
override fun onDestroy() {
exoPlayer?.stop()
exoPlayer?.release()
exoPlayer = null
mediaSession?.release()
mediaSession = null
CacheController.release()
super.onDestroy()
}
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaLibrarySession? {
return mediaSession
}
}
AndroidManifest.xml code:
<service
android:name="cn.xybbz.common.music.ExampleLibraryPlaybackService"
android:exported="true"
android:foregroundServiceType="mediaPlayback">
<intent-filter>
<action android:name="androidx.media3.session.MediaSessionService" />
<action android:name="android.media.browse.MediaBrowserService"/>
</intent-filter>
</service>
Please can you provide more information:
- What version of media3 are you using?
- What versions of Android are you testing/observing on?
- Please provide screenshots showing what you observe
Hey @xianyvbang. We need more information to resolve this issue but there hasn't been an update in 14 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!