Youtube Exit Full Screen Mode TextView Visibility Issue

前端 未结 1 1412
深忆病人
深忆病人 2021-01-16 23:18

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

相关标签:
1条回答
  • 2021-01-17 00:13

    _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();
    }
    }
    
    0 讨论(0)
提交回复
热议问题