我正在以全屏模式播放视频,当我单击“后退”按钮时,我可以退出全屏模式-但无法显示TextView(在全屏情况下隐藏).
要在全屏模式下隐藏textView,我使用以下代码:
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
showPlayer();
videoPlayer = player;
videoPlayer.setOnFullscreenListener(new OnFullscreenListener() {
@Override
public void onFullscreen(boolean _isFullScreen) {
fullScreen = _isFullScreen;
textView.setVisibility(View.GONE); // hiding
}
});
videoPlayer.loadVideo(actualVideo.getVideoId());
}
}
若要显示textView,当我使用以下方法退出全屏模式时:
@Override
public void onBackPressed() {
if (fullScreen){
videoPlayer.setFullscreen(false);
textView.setVisibility(View.VISIBLE); // showing
} else{
super.onBackPressed();
}
}
不知道为什么但是,当我点击后退按钮时(我的意思是退出全屏模式),我的textView并没有处于可见状态.
解决方法:
_isFullScreen处于public void onFullscreen(boolean _isFullScreen)内为全屏状态,如果为true,则表示播放器已进入全屏模式;如果为false,则表示播放器已从全屏模式切换回,并且两次都调用了此侦听器当您进入全屏模式并从全屏模式返回时分别具有true和false值.您应按以下方式修改代码
videoPlayer.setOnFullscreenListener(new OnFullscreenListener() {
@Override
public void onFullscreen(boolean _isFullScreen) {
fullScreen = _isFullScreen;
if(_isFullScreen){
textView.setVisibility(View.GONE); // hide text as player switched to full screen mode
} else {
textView.setVisibility(View.VISIBLE); // show text as player switched back from full screen mode, changing visibility here instead of onBackPressed have advantage that even if user switches back from full screen mode using control button on player instead of press back button the text will still come to visible
}
}
});
如果按下返回按钮时播放器处于全屏模式,则onBackPressed侦听器仅用于将播放器从全屏模式切换回;
@Override
public void onBackPressed() {
if (fullScreen){
videoPlayer.setFullscreen(false);
} else{
super.onBackPressed();
}
}