Android: How to upload a YouTube channel to WebView?

I am trying to create a page in an application that loads a YouTube channel inside a WebView. Almost everything works for me, except for the actual video playback. As if inside a WebView, when I click on a video to play it, the message is lost. I do not see a call to the shouldOverrideUrlLoading () function, as expected.

The code:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.webview);
        webView = (WebView)findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new webViewClient());
        webView.loadUrl(getIntent().getStringExtra("url"));
    }   

    private class webViewClient extends WebViewClient {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.equals("about:blank")) {
                return true;
            }
            view.loadUrl(url);
            return true;
        }
    }

The download URL is as follows: http://www.youtube.com/tinhtevideo . Am I missing something? I would make exepct that shouldOverridingUrlLoading () would be called with a URL like "vnd.youtube:", but I never saw it.

Of course, if I load the above URL in the Android browser, everything works fine.

+3
1

html , . - .

<iframe width="560" height="315" 
        src="http://www.youtube.com/embed/{{video}}?autoplay=1" 
        frameborder="0" 
        allowfullscreen>
</iframe>

html -.

private String myHtmlData = "";    //myHtmlData is my html file
myWebView.setBackgroundColor(Color.TRANSPARENT);
WebSettings settings = myWebView.getSettings();
settings.setJavaScriptEnabled(true);  
settings.setPluginsEnabled(true);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
myHtmlData, "text/html", "utf-8", null);
myWebView.loadData(myHtmlData, "text/html", "utf-8"); 

, html .

getAssets().open(fileName);

, .

+1

Source: https://habr.com/ru/post/1790750/


All Articles