Youtube 退出全屏模式 TextView 可见性问题 [英] Youtube Exit Full Screen Mode TextView Visibility Issue

查看:32
本文介绍了Youtube 退出全屏模式 TextView 可见性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在全屏模式下播放视频,当我点击后退按钮时,我能够退出全屏模式 - 但无法显示我在全屏时隐藏的 TextView.

I am playing video in a full screen mode, and when I do click on back button I am able to exit full screen mode - but not able to show TextView which I have hide in case of full screen.

要在全屏模式下隐藏 textView,我使用以下代码:

To Hide textView on Full Screen mode, I am using below code:

@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,当我退出全屏模式时使用:

To show textView, when I Exit Full Screen mode using:

@Override
public void onBackPressed() {
    if (fullScreen){
        videoPlayer.setFullscreen(false);
        textView.setVisibility(View.VISIBLE); // showing

    } else{
        super.onBackPressed();
    }
}

我不知道为什么?但是当我点击后退按钮(我的意思是退出全屏模式)时,我的 textView 并没有处于可见状态.

I don't know why? But I am not getting my textView as in visible state, when I do tap on back button (I mean exit full screen mode).

推荐答案

_isFullScreen inside public void onFullscreen(boolean _isFullScreen) 为全屏状态,如果为真则表示播放器已全屏模式,如果为假,则意味着播放器从全屏模式切换回来,当您进入全屏模式和从全屏模式返回时,都会调用此侦听器,分别具有 true 和 false 值.您应该修改代码如下

_isFullScreen inside public void onFullscreen(boolean _isFullScreen) is state of full screen, if it's true it means player is gone to full screen mode and if it is false it means the player is switched back from full screen mode and this listener is called both times when you go to full screen mode and come back from full screen mode with true and false value respectively. You should modify code as below

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 侦听器将仅用于将播放器从全屏模式切换回来;

while your onBackPressed listener will be just used for switching player back from full screen mode if player was in full screen mode when back button was pressed;

@Override
public void onBackPressed() {
if (fullScreen){
    videoPlayer.setFullscreen(false);

} else{
    super.onBackPressed();
}
}

这篇关于Youtube 退出全屏模式 TextView 可见性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆