18

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?

Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236
  • Just a long shot, have you messed with using the System.setProperty("http.keepAlive", "false"); tag on your Url connection? Possibly it is caching some older connection and jumping right to where it left off when you try to reuse it. – thomas.cloud May 09 '12 at 00:09
  • interesting thought... I'll give it a whirl, though I doubt that's it given that I'm trying it out with random YouTube videos, so, there's no reason for it to have had anything to have cached. – Yevgeny Simkin May 09 '12 at 01:19
  • A shot in the dark. When you load this page in your webView, what is the origin of the page? Is it on the local device or on a server somewhere? Just wondering if you could be getting blocked by same-origin policy. – Error 454 May 10 '12 at 23:02
  • Also, additional questions: Have you logged calls to shouldOverrideUrlLoading and onReceivedError in your WebViewClient implementation? Or are you using WebChromeClient instead of WebViewClient? – Error 454 May 10 '12 at 23:04

2 Answers2

2

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

BoD
  • 10,838
  • 6
  • 63
  • 59
  • that's very interesting, thanks! I'll definitely check it out. – Yevgeny Simkin May 20 '12 at 21:57
  • Interesting... so, when I re-compiled this for 3.0 and added hardware acceleration support, everything works correctly! However, back in 2.3.x without hardware support (there was none back in THOSE days) the problem persists. So, it would appear that this is not a WebView configuration item so much as a resource allocation issue of some sort. I guess WebView got short shrifted back in the Gingerbread days. I suppose there's not much to do about it. Also, I just tested it in 3.2 without HA and it doesn't work. So, HA is the solution. – Yevgeny Simkin May 20 '12 at 22:15
  • 1
    Cool ;) Oh and one more thing: it seems there soon will be an official YouTube sdk for Android: https://developers.google.com/events/io/sessions/gooio2012/120/ – BoD May 20 '12 at 22:31
0

I don't know much about android. But go through following links which can be useful for you.

WebView provides no browser-like widgets, does not enable JavaScript and web page errors are ignored. If your goal is only to display some HTML as a part of your UI, this is probably fine; the user won't need to interact with the web page beyond reading it, and the web page won't need to interact with the user. If you actually want a full-blown web browser, then you probably want to invoke the Browser application with a URL Intent rather than show it with a WebView,browser view is more customised for small screen.

  1. http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application
  2. How to play a video in a webview with android?
  3. UIWebView to Play Local and downloaded Video
  4. Android play youtube video in webview
  5. Video streaming using RTSP: Android
Community
  • 1
  • 1
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
  • I will look through your links (and thanks for assembling them) but your initial assertion is fundamentally false. WebView IS the browser. Some things are disabled by default (like js & plugins), turning them on is done by calling a method that flags them on. I'm pretty sure that I'm just missing something, given that the YouTube flash plugin does *work, it just skips video playback! – Yevgeny Simkin May 10 '12 at 17:24
  • so... as a follow up, I've reviewed your links and unfortunately none of them speak to this issue. People are either trying to stream video directly or play YouTube in the YouTube player, which is all well and good, but doesn't actually address the topic at hand. Unfortunately "not knowing much about Android" isn't going to be the area of expertise that will help you help me with this problem. :) – Yevgeny Simkin May 10 '12 at 22:51