java 如何在exoplayer中检测播放或暂停动作

vlju58qv  于 2022-12-21  发布在  Java
关注(0)|答案(1)|浏览(177)

我已经实现了exoplayer通知管理器,并希望检测播放或暂停动作,以便我可以相应地更新用户界面
我试过这个代码
'

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
    }
  }
});

'
我从这里得到的-https://stackoverflow.com/a/48067205/13312583
但是它不起作用,这件事有什么方法吗?

xzabzqsa

xzabzqsa1#

您可以用途:

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

        }

    }

}

相关问题