在 Amazon Fire TV 上使用麦克风搜索后如何使视频正常恢复?
How to make video resume properly after microphone search used on Amazon Fire TV?
我正在使用 Google Leanback 代码为 Amazon Fire TV 创建一个视频播放器应用程序(我知道它不是为 Fire TV 而设计的,但我已经完成了让它工作所需的一切 - 除了这个)。我已经做到了,如果您按下主页按钮退出应用程序,或者如果您暂停它,观看不同的视频,然后返回,视频会从您中断的地方继续播放。
但是,亚马逊拒绝了我的应用程序,因为如果您在视频播放时进行麦克风搜索然后返回,视频将重新开始而不是继续播放。
我错过了什么?这是我在 PlayerActivity 中用于 startVideoPlayer() 和 onPause() 的代码:
private void startVideoPlayer() {
Bundle bundle = getIntent().getExtras();
mSelectedMovie = (Movie) getIntent().getSerializableExtra( VideoDetailsFragment.EXTRA_MOVIE );
if( mSelectedMovie == null || TextUtils.isEmpty( mSelectedMovie.getVideoUrl() ) || bundle == null )
return;
mShouldStartPlayback = bundle.getBoolean( VideoDetailsFragment.EXTRA_SHOULD_AUTO_START, true );
sprefs = PreferenceManager.getDefaultSharedPreferences(this);
startPosition = sprefs.getInt(mSelectedMovie.getVideoUrl(), 0);
mVideoView.setVideoPath( mSelectedMovie.getVideoUrl() );
if ( mShouldStartPlayback ) {
mPlaybackState = PlaybackState.PLAYING;
updatePlayButton( mPlaybackState );
if ( startPosition > 0 ) {
mVideoView.seekTo( startPosition );
}
mVideoView.start();
mPlayPause.requestFocus();
startControllersTimer();
} else {
updatePlaybackLocation();
mPlaybackState = PlaybackState.PAUSED;
updatePlayButton( mPlaybackState );
}
}
@Override
protected void onPause() {
super.onPause();
if ( mSeekbarTimer != null ) {
mSeekbarTimer.cancel();
mSeekbarTimer = null;
}
if ( mControllersTimer != null ) {
mControllersTimer.cancel();
}
mVideoView.pause();
mPlaybackState = PlaybackState.PAUSED;
updatePlayButton( mPlaybackState );
SharedPreferences.Editor editor = sprefs.edit();
editor.putInt(mSelectedMovie.getVideoUrl(), mVideoView.getCurrentPosition());
editor.apply();
}
我最终不得不在 onResume 中调用 startVideoPlayer,如下所示:
@Override
public void onResume() {
super.onResume();
startVideoPlayer();
}
我正在使用 Google Leanback 代码为 Amazon Fire TV 创建一个视频播放器应用程序(我知道它不是为 Fire TV 而设计的,但我已经完成了让它工作所需的一切 - 除了这个)。我已经做到了,如果您按下主页按钮退出应用程序,或者如果您暂停它,观看不同的视频,然后返回,视频会从您中断的地方继续播放。
但是,亚马逊拒绝了我的应用程序,因为如果您在视频播放时进行麦克风搜索然后返回,视频将重新开始而不是继续播放。
我错过了什么?这是我在 PlayerActivity 中用于 startVideoPlayer() 和 onPause() 的代码:
private void startVideoPlayer() {
Bundle bundle = getIntent().getExtras();
mSelectedMovie = (Movie) getIntent().getSerializableExtra( VideoDetailsFragment.EXTRA_MOVIE );
if( mSelectedMovie == null || TextUtils.isEmpty( mSelectedMovie.getVideoUrl() ) || bundle == null )
return;
mShouldStartPlayback = bundle.getBoolean( VideoDetailsFragment.EXTRA_SHOULD_AUTO_START, true );
sprefs = PreferenceManager.getDefaultSharedPreferences(this);
startPosition = sprefs.getInt(mSelectedMovie.getVideoUrl(), 0);
mVideoView.setVideoPath( mSelectedMovie.getVideoUrl() );
if ( mShouldStartPlayback ) {
mPlaybackState = PlaybackState.PLAYING;
updatePlayButton( mPlaybackState );
if ( startPosition > 0 ) {
mVideoView.seekTo( startPosition );
}
mVideoView.start();
mPlayPause.requestFocus();
startControllersTimer();
} else {
updatePlaybackLocation();
mPlaybackState = PlaybackState.PAUSED;
updatePlayButton( mPlaybackState );
}
}
@Override
protected void onPause() {
super.onPause();
if ( mSeekbarTimer != null ) {
mSeekbarTimer.cancel();
mSeekbarTimer = null;
}
if ( mControllersTimer != null ) {
mControllersTimer.cancel();
}
mVideoView.pause();
mPlaybackState = PlaybackState.PAUSED;
updatePlayButton( mPlaybackState );
SharedPreferences.Editor editor = sprefs.edit();
editor.putInt(mSelectedMovie.getVideoUrl(), mVideoView.getCurrentPosition());
editor.apply();
}
我最终不得不在 onResume 中调用 startVideoPlayer,如下所示:
@Override
public void onResume() {
super.onResume();
startVideoPlayer();
}