15

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?

rmtheis
  • 5,992
  • 12
  • 61
  • 78
Jimmy
  • 10,427
  • 18
  • 67
  • 122
  • Take a look at http://stackoverflow.com/questions/8475707/youtube-video-in-webview-doesnt-load. The guy had the same problem and seemed to get it working. Some of the comments suggest otherwise, but this may work for you. – speedynomads Jan 09 '13 at 17:56
  • You can take a look [this question and answer](http://stackoverflow.com/questions/14156411/loading-youtube-video-through-i-frame-in-android-webview). It's pretty much the same with your problem. – Eikyi Oct 10 '13 at 09:59
  • any answer for this ? – Code_Life Jun 05 '14 at 11:01

4 Answers4

4

You have to put this in your manifest

<application android:hardwareAccelerated="true" ...>
Pablo Martinez
  • 1,573
  • 12
  • 31
2

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());
Pauland
  • 1,974
  • 16
  • 25
1

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.

Community
  • 1
  • 1
wayne_bai
  • 1,218
  • 4
  • 14
  • 23
0

iframe works for me. But, I found out, when using Android Emulator on Windows for you tube video, the internet on Emulator will stop working after a while and I need to restart the emulator to get internet access. This has never happened on a Android Phone.

So, just check it on your browser to make sure there is internet connection.

linamm
  • 1