Youtube Exit Full Screen Mode TextView Visibility Issue

拥有回忆 提交于 2019-12-01 14:00:40

问题


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.

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

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

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).


回答1:


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

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


来源:https://stackoverflow.com/questions/34329549/youtube-exit-full-screen-mode-textview-visibility-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!