如何解决ExoPlayer:即将转换媒体项的侦听器
我尝试使用 onMediaItemTransition 侦听器记录用户在视频中点击“跳过”的时间。但是,它改为记录 0 分 0 秒。如果我以其他方式离开视频,它会正确记录时间戳。
这是我的代码:
@Override
public void onMediaItemTransition(MediaItem mediaItem,@Player.MediaItemTransitionReason int reason) {
playbackPosition = player.getCurrentPosition(); // instance variable
if (reason == ExoPlayer.MEDIA_ITEM_TRANSITION_REASON_AUTO) {
mFirebaseAnalytics.logEvent("video_completed_intro",null);
} else if (reason == ExoPlayer.MEDIA_ITEM_TRANSITION_REASON_SEEK) {
mFirebaseAnalytics.logEvent("skipped_intro",null);
logExitTime();
}
mFirebaseAnalytics.logEvent("meditation_video_start",null);
}
private void logExitTime() {
// Record exit time if not reached the end of the playlist.
if (player.getPlaybackState() != ExoPlayer.STATE_ENDED) {
int minutes = (int) Math.floor(playbackPosition / 60000.0);
int remainderSeconds = (int) (playbackPosition / 1000.0) - minutes * 60;
if (playbackPosition >= 30000) {
// Round down to nearest 30 seconds if total less than 30 seconds.
remainderSeconds = remainderSeconds < 30000 ? 0: 30;
} // Otherwise,if user never made it past 30 seconds,report the actual # of seconds
String video = currentWindow == 0 ? "intro" : "main";
mFirebaseAnalytics.logEvent(String.format("exit_video_%s_%dm_%ds",video,minutes,remainderSeconds),null);
mFirebaseAnalytics.logEvent(String.format("video_not_completed_%s",video),null);
}
}
文档说“在播放转换到媒体项时调用”——所以我认为它可能会在重置当前视频后但在完全切换到下一个视频之前被调用。
从 ExoPlayer 文档来看,我没有看到更好的方法;我打算尝试只听“跳过”按钮的点击,但想知道其他人是否知道更好的方法,或者我是否可能面临已知的陷阱。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。