I use Exoplayer and bind with PlayerNotificationManager to handle player action on the notification. It works fabulous but I want to get a listener or receiver when stop button pressed from notification. Right now when I click on the stop button player was stuck.
playerNotificationManager = PlayerNotificationManager.createWithNotificationChannel(
this,
"playback_channel",
R.string.exo_download_notification_channel_name,
1,
object : PlayerNotificationManager.MediaDescriptionAdapter {
override fun createCurrentContentIntent(player: Player?): PendingIntent? {
val intent = Intent(context, PlayerExoActivity::class.java)
return PendingIntent.getActivity(
context,
1,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
)
}
override fun getCurrentContentText(player: Player?): String? {
return "Day " + chapterName
}
override fun getCurrentContentTitle(player: Player?): String {
return courseName!!
}
override fun getCurrentLargeIcon(
player: Player?,
callback: PlayerNotificationManager.BitmapCallback?
): Bitmap? {
return largeIcon
}
}
)
This is a receiver to handle other things while Exoplayer state change.
override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
if (playbackState == ExoPlayer.STATE_BUFFERING) {
val intent = Intent("com.example.exoplayer.PLAYER_STATUS")
intent.putExtra("state", PlaybackStateCompat.STATE_BUFFERING)
broadcaster?.sendBroadcast(intent)
} else if (playbackState == ExoPlayer.STATE_READY) {
val intent = Intent("com.example.exoplayer.PLAYER_STATUS")
if (playWhenReady) {
intent.putExtra("state", PlaybackStateCompat.STATE_PLAYING)
} else {
intent.putExtra("state", PlaybackStateCompat.STATE_PAUSED)
}
broadcaster?.sendBroadcast(intent)
} else if (playbackState == ExoPlayer.STATE_ENDED) {
val intent = Intent("com.example.exoplayer.PLAYER_STATUS")
intent.putExtra("state", PlaybackStateCompat.STATE_STOPPED)
broadcaster?.sendBroadcast(intent)
}
}