0

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 ?

Garvit
  • 37
  • 7
  • As far as I'm concerned, this is the only way to listen to playback state. I guess there's either problem in the code for updating UI or you're accessing the wrong player variable. – ganjaam Nov 11 '22 at 16:05
  • @ganjaam this method is deprecated – Garvit Nov 11 '22 at 17:20

1 Answers1

1

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

        }

    }

}