YosiFZ
YosiFZ

Reputation: 7900

WebView load youtube page

I am try to load YouTube page inside a WebView:

webview = (WebView) findViewById(R.id.webview);
webview.loadUrl(new String("http://youtube.com"));

But every time i done it instead of show me the page content inside the WebView it open me a Open With Menu, any idea how i can show the youtube page?

Upvotes: 0

Views: 64

Answers (1)

Nikhil Borad
Nikhil Borad

Reputation: 2085

        mWebView = (WebView) findViewById(R.id.webView);
        WebSettings settings = mWebView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setAllowFileAccess(true);
        if (Build.VERSION.SDK_INT > 7) {
            settings.setPluginState(PluginState.ON);
        } else {
            settings.setPluginsEnabled(true);
        }

        String html = "";
        html += "<html><body>";
        html += "<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/MU9Srs04sFU?rel=0\" frameborder=\"0\" allowfullscreen></iframe>";
        html += "</body></html>";

mWebView.loadData(html, "text/html", null);

May this logic(hint) helps you..

Upvotes: 1

Related Questions