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

时间:2015-12-17 08:08:16

标签: android youtube textview youtube-api android-youtube-api

我正在以全屏模式播放视频,当我点击后退按钮时,我可以退出全屏模式 - 但是无法显示我在全屏时隐藏的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视为处于可见状态。

1 个答案:

答案 0 :(得分:1)

public void onFullscreen(boolean _isFullScreen)内的

_isFullScreen是全屏状态,如果是真的则表示播放器进入全屏模式,如果是假,则表示播放器从全屏模式切换回来,这个监听器都被调用进入全屏模式并分别从具有真值和假值的全屏模式返回的时间。你应该修改如下代码

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();
}
}