Android - WebView not playing YouTube videos

前端 未结 3 2015
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-19 03:11

I have some WebView code with which I am trying to play YouTube videos on a YouTube channel. But all it is doing is showing the spinner icon on a video and never actually st

3条回答
  •  庸人自扰
    2021-01-19 03:44

    Have you tried using your own WebChromeClient? This question seems relevant. WebView and HTML5

    You'll need to create one of these and implement it yourself, similar to what you're doing for the WebViewClient.

    webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onShowCustomView(View view, CustomViewCallback callback) {
            super.onShowCustomView(view, callback);
            if (view instanceof FrameLayout) {
                FrameLayout frame = (FrameLayout) view;
                if (frame.getFocusedChild() instanceof VideoView) {
                    VideoView video = (VideoView) frame.getFocusedChild();
                    frame.removeView(video);
                    a.setContentView(video);
                    video.setOnCompletionListener(this);
                    video.setOnErrorListener(this);
                    video.start();
                }
            }
        }
    });
    

    Make sure you add webview.getSettings().setPluginsEnabled(true); to your webview settings.

    And most importantly, for any webpage to load in a WebView, be sure to have the INTERNET permission in your Manifest:

    
    

提交回复
热议问题