delight-im / Android-AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box
MIT License
2.39k stars 574 forks source link

Video In Webview Not Playing in Full Screen. Screen Hangs when you click full screen icon #199

Closed Samyak81 closed 3 years ago

Samyak81 commented 6 years ago

Youtue video or html video. If you click full screen icon. It will hang the screen and nothing works.

yashrs commented 6 years ago

Same here.. I will be very grateful if you can provide us with a solution to this.

Did you find a solution @Samyak81 ?

appstute-pratik commented 5 years ago

Same with me, Is there any solution?

xiaoxing1992 commented 5 years ago

跟我一样,有什么办法吗?

zuhairabbs commented 4 years ago

Hi, I am facing same issue while using Advance webview, Screen hangs whenever i click full screen button while playing youtube video

drounder commented 4 years ago

please provide us full control over the full screen, we will be rally grateful for this.

1008k commented 4 years ago

In my case, there was a problem displaying full screen ads.

So, the library is included in the project, and "pauseTimers ();" and "resumeTimers ();" in "AdvancedWebView.java" are disabled and used.

poinear commented 4 years ago

did anyone got the solution for this fullscreen problem

fisal77 commented 4 years ago

https://stackoverflow.com/a/24929961

AadarshaSadan commented 3 years ago

does any one got this solution or solved in library ?

AadarshaSadan commented 3 years ago

//copy this code after protected void onCreate(Bundle savedInstanceState){....} private class myChrome extends WebChromeClient { private View mCustomeview; private WebChromeClient.CustomViewCallback mcustomViewCallback;

    private int mOrginalSystemVisiblity;

    myChrome() {

    }

    public Bitmap getDefaultVideoPoster() {
        if (mCustomeview == null) {
            return null;
        }

        return BitmapFactory.decodeResource(getApplicationContext().getResources(),2130837573);
    }

    public  void onHideCustomView()
    {
        ((FrameLayout)getWindow().getDecorView()).removeView(this.mCustomeview);
        this.mCustomeview=null;
        getWindow().getDecorView().setSystemUiVisibility(this.mOrginalSystemVisiblity);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        this.mcustomViewCallback.onCustomViewHidden();
        this.mcustomViewCallback=null;
    }

    public  void onShowCustomView(View paramView,WebChromeClient.CustomViewCallback paraCustomeViewcallback)
    {
        if(this.mCustomeview !=null)
        {
            onHideCustomView();
            return;
        }
        this.mCustomeview=paramView;
        this.mOrginalSystemVisiblity=getWindow().getDecorView().getSystemUiVisibility();
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        this.mcustomViewCallback=paraCustomeViewcallback;
        ((FrameLayout)getWindow().getDecorView()).addView(this.mCustomeview,new FrameLayout.LayoutParams(-1,-1));
        getWindow().getDecorView().setSystemUiVisibility(3846);
    }

}
AadarshaSadan commented 3 years ago

and just before loading url call this function

    mWebView.setWebViewClient(new WebViewClient());
    mWebView.setWebChromeClient(new myChrome());
sawyerhnn commented 3 years ago

Hi @AadarshaSadan I get nullpoint in the code getWindow().getDecorView(). Can you please help me fix that?

this.mOrginalSystemVisiblity=getWindow().getDecorView().getSystemUiVisibility();

HosseinArabbeigi commented 3 years ago

When fullscreen button clicked, chrome client gives us fullscreen view and then we should add it to our activity view :

Define this variable global to hold fullscreen view reference in our activity:

public class MyAmazingActivity extends AppCompatActivity {
    private View fullscreenView;
    //...
}

Then web chrome client will notify us about showing and hiding fullscreen view in onShowCustomView and onHideCustomView methods:

WebChromeClient webChromeClient = new WebChromeClient() {

            private ViewGroup rootView;
            private WebChromeClient.CustomViewCallback customViewCallback;

            @Override
            public void onShowCustomView(View view, CustomViewCallback callback) {

                //Destroy full screen view if already exists
                if (fullscreenView != null) {
                    callback.onCustomViewHidden();
                    return;
                }

                //Layout params to fit fullscreen view in our activity
                ViewGroup.LayoutParams layoutParams = 
                        new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                ViewGroup.LayoutParams.MATCH_PARENT);
                //Catch root of current activity to add fullscreen view
                rootView = (ViewGroup) WebViewBaseActivity.this.webView.getRootView();

                //Store full screen view, we need it to destroy it out of scope
                fullscreenView = view;

                customViewCallback = callback;
                rootView.addView(fullscreenView, layoutParams);
            }

            @Override
            public void onHideCustomView() {
                //Make sure fullscreen view exists
                if (fullscreenView != null) {

                    //Remove fullscreen view from activity root view
                    rootView.removeView(fullscreenView);
                    fullscreenView = null;

                    //Tell browser we did remove fullscreen view
                    customViewCallback.onCustomViewHidden();
                }
            }

        };

And finally removing fullscreen view when back pressed(User expects this behaviour):

@Override
public void onBackPressed() {
    if (fullscreenView != null) {
        webChromeClient.onHideCustomView();
    }
}       
ocram commented 3 years ago

Please see https://github.com/delight-im/Android-AdvancedWebView/issues/84