Reputation: 47
I have implemented exoplayer notification manager and wanted to detect play or pause action so that I can update UI accordingly to it
I have tried this code
`
player.addListener(new Player.DefaultEventListener() {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (playWhenReady && playbackState == Player.STATE_READY) {
// media actually playing
} else if (playWhenReady) {
// might be idle (plays after prepare()),
// buffering (plays when data available)
// or ended (plays when seek away from end)
} else {
// player paused in any state
}
}
});
`
which I got from here - https://stackoverflow.com/a/48067205/13312583
but its not working is there any method to this thing ?
Upvotes: 0
Views: 708
Reputation: 172
You can use:
override fun onPlaybackStateChanged(playbackState: Int) {
super.onPlaybackStateChanged(playbackState)
when (playbackState) {
ExoPlayer.STATE_BUFFERING -> {
//I send a broadcast from my exoplayer service to my interface
}
ExoPlayer.STATE_READY -> {
//I send a broadcast from my exoplayer service to my interface
}
Player.STATE_IDLE -> {
//I send a broadcast from my exoplayer service to my interface
}
}
}
Upvotes: 1