Converted Website into Android App and Youtube Videos From my Website Doesn't go in full screen mode

后端 未结 1 505
渐次进展
渐次进展 2021-01-29 07:41

I converted a website into an app with WebView in Android Studio. Everything is fine but the youtube videos that was in my website does not go in full Screen. I am a beginner, s

相关标签:
1条回答
  • 2021-01-29 08:22

    To achieve this follows these steps :
    1) Set WebChromeClient to your webview.
    Exmaple : WebView.setWebChromeClient(new MyChromeBrowser());
    2) Implement method onShowCustomView() and onHideCustomView() inside your WebChromeClient.
    Example : `

    private class MyChromeBrowser extends WebChromeClient {
        @Override
        public void onShowCustomView(View view, CustomViewCallback callback) {
            super.onShowCustomView(view, callback);
        }
    
        @Override
        public void onHideCustomView() {
            super.onHideCustomView();
        }
    }`
    


    3) Give android:hardwareAccelerated="true" in manifest file for your activity.
    Example : <activity android:name=".MainActivity" android:hardwareAccelerated="true" />
    Update :
    To fix this try these :
    change these lines : webView.setWebChromeClient(new MyWebChromeClient()); to

    mWebChromeClient = new myWebChromeClient();
    webView.setWebChromeClient(mWebChromeClient);
    

    inside initWebView() method.

    To let the system decide the best orientation in full-screen mode add this line to onShowCustomView(View view, CustomViewCallback callback) method:

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    


    UPDATE : 09-07-2017
    Or you can use a VideoEnabledWebView library for full screen viedo player in webview and much more .
    Link : GitHub

    0 讨论(0)
提交回复
热议问题