Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Android WebView is not loading youtube HTML5 iframe video?

I tried the following:

    WebView wv = (WebView) findViewById(R.id.webView1);
    String playVideo= "<html><body><iframe width='200' height='143' src='http://www.youtube.com/embed/JW5meKfy3fY' frameborder='0' allowfullscreen></iframe></body></html>";
    wv.getSettings().setPluginsEnabled(true);
    wv.getSettings().setAllowFileAccess(true);
    wv.getSettings().setPluginState(PluginState.ON);
    wv.getSettings().setBuiltInZoomControls(true);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.loadData(playVideo, "text/html", "utf-8");

I only see thumbnail and then when I click on it the frame turns to black and does not load the video. I'm targeting API 15 and I have internet permission. How could I run the html5 youtube iframe video in Android webview?

like image 811
Jimmy Avatar asked Aug 09 '12 22:08

Jimmy


3 Answers

You have to put this in your manifest

<application android:hardwareAccelerated="true" ...>
like image 89
Pablo Martinez Avatar answered Nov 04 '22 05:11

Pablo Martinez


On Android 3.0++, you must activate Hardware acceleration if your android:targetSdkVersion is lower than 11. And, you must add this line:

wv.setWebChromeClient(new WebChromeClient());
like image 2
Pauland Avatar answered Nov 04 '22 05:11

Pauland


You are running on 2.3(GingerBread) or 4.0(ice Cream)?

If you are running on Ice Cream, you need to enable hardware acceleration.

If you are running on GingerBread, please refer to: WebView and HTML5 <video>

Hope this helpgul.

like image 1
wayne_bai Avatar answered Nov 04 '22 06:11

wayne_bai