Youtube 退出全屏模式 TextView 可见性问题

Youtube Exit Full Screen Mode TextView Visibility Issue

我正在全屏模式下播放视频,当我点击后退按钮时,我可以退出全屏模式 - 但无法显示我在全屏情况下隐藏的 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 inside 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();
}
}