Exoplayer 2.5.3获取时间,下一首歌将获得播放exoplayer android

时间:2017-10-10 13:19:45

标签: android exoplayer

我希望在下一首歌能够播放时获得准确的timestamp。当前的歌曲即将结束。 我正在使用

  

实施' com.google.android.exoplayer:exoplayer:r2.5.3'

1 个答案:

答案 0 :(得分:0)

点击按钮,我打印了这样的日志:

Log.e("TAG", "Duration: " + (mPlayer.getDuration() / 1000) + "s.");
Log.e("TAG", "Current: " + (mPlayer.getContentPosition() / 1000) + "s.");
Log.e("TAG", "Left: " + ((mPlayer.getDuration() - mPlayer.getContentPosition()) / 1000) + "s.");

这是我得到的:

D:=> onVideoTapped

E:持续时间:287秒。

E:当前:0s。

E:左:286s。

D:=> onVideoTapped

E:持续时间:287秒。

E:当前:6s。

E:左:281s。

再次检查您的计算。祝你好运!

<强>更新

我再次检查了它,看起来我得到了正确的时间:

14:43:27 - onVideoTapped()           => onVideoTapped
14:43:27 - log()                     => Duration: 596s.   Current: 595s.
14:43:27 - log()                     => Left: 1s.
14:43:28 - onTracksChanged()         => currentWindowIndex: 1  nextWindowIndex: 2 isPlayBackStateReady: true
14:43:28 - log()                     => Duration: 596s.   Current: 596s.
14:43:28 - log()                     => Left: 0s.
14:43:31 - onVideoTapped()           => onVideoTapped
14:43:31 - log()                     => Duration: 510s.   Current: 2s.
14:43:31 - log()                     => Left: 507s.