Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's different between using WebView and Browser for YouTube Video api?

I've implemented the youtube api and it works as expected in a regular computer browser. When I test it in both Ice Cream Sandwich and Gingerbread, on the stock Browser (which is Webkit) it also works exactly as it does on my computer.

However, when I load it into a WebView it experiences some very odd behavior. Specifically, it loads all the player controls (play button, progress bar, etc) and fires all the normal events for buffering and playing, but then rather than playing, it just skips to the end and displays the standard YouTube post-playback icons for other videos. If I click on one of those icons, it then skips that video and jumps straight to the end of that video.

I have setJavascriptEnabled and setPluginsEnabled both set to true. I assume I'm missing something, since it all works fine in the stock browser, but I'm stumped as to what it is. Has anyone implemented the YouTube Video player (or JWPlayer, or anything with which I can play youtube videos) in a WebView? And if so, please share how you managed to get it to work.

TIA

[EDIT] Since posting this, I've implemented a native player that retrieves video streams directly from YouTube. This is INCREDIBLY clunky because the fragmentation between devices relating to which files they can/cannot play is *really huge, and since there's no way to pass YouTube a device model and have it return the relevant streams, what happens is that you get all the streams and then have to pick from the array. Anyway... the point is that this is just a dreadful approach and I'd really love to figure out the good ole' embedded player solution, since it *must work, given that it works in the stock browser. Could this be a headers issue?

like image 767
Yevgeny Simkin Avatar asked Apr 11 '12 10:04

Yevgeny Simkin


People also ask

How do I open YouTube in WebView?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken web view to show youtube app.

Which browser is used in Android WebView?

The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout. Since Android 4.4, it is based on the Chrome on Android v33.


1 Answers

Have you tried this by any chance: http://code.google.com/p/html5webview/source/browse/trunk/HTML5WebView/src/org/itri/html5webview/HTML5WebView.java

Basically the tag doesn't work on a 'default' WebView without some complicated and not really documented configuration. Please tell us if that fixes your problems.

Please also see this issue: http://code.google.com/p/android/issues/detail?id=22254

like image 139
BoD Avatar answered Oct 13 '22 22:10

BoD