Zookey Zookey - 2 months ago 33
Android Question

How to play YouTube video inside Android WebView?

I am making RSS reader application, and I get RSS data from URL, and that RSS data can contain link to YouTube video.

Here is an example how link to youtube vide looks like:

div class="video-shortcode"><iframe title="YouTube video player" width="600"
height="350" src="http://www.youtube.com/embed/HXrcUyCVA6c"
frameborder="0" allowfullscreen></iframe></div>


And when I run my application, there is no video, its all black, and I can't play it.

How I can play video inside WebView?

EDIT:
Here is the result:

enter image description here

Here is my code:

// set webview properties
WebSettings ws = desc.getSettings();
ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
ws.getPluginState();
ws.setPluginState(PluginState.ON);
ws.setJavaScriptEnabled(true);
ws.setUserAgent(0);
ws.setJavaScriptCanOpenWindowsAutomatically(true);

desc.setWebChromeClient(new WebChromeClient() {
});
desc.loadDataWithBaseURL("http://www.balkanandroid.com/", feed
.getItem(pos).getContent(), "text/html", "UTF-8", null);


I have android:hardwareAccelerated="true" in my AndroidManifest.xml.

Answer

Probably not of any use, but it might be handy for future people (Hey future people).

But remove this line:

ws.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

and make sure javascript is enabled

ws.setJavaScriptEnabled(true);

These two lines caused me quite a lot of trouble when I was starting out.

Comments