How do I get the YouTube preview image to show up in an Android WebView?
I realize there are a lot of YouTube in WebView questions but they don't seem to address my problem exactly.
I am loading a website with an embedded YouTube clip in a WebView, the problem is the YouTube preview image does not 开发者_StackOverflow社区appear, I just get a black box with YouTube at the bottom.
This same website loads the preview image in the Android browser. The phone does not have Flash.
I understand it cant play the video without flash, I don't want it to play in the WebView, I just need the preview to load like it does in the regular browser.
I cant edit the website itself but it seems to be using this for the YouTube video.
<iframe allowfullscreen="" frameborder="0" height="271" src="http://www.youtube.com/embed/28L-hOJHwUw?rel=0&hd=1" width="475"></iframe></div>
I am enabling both Javascript and Plugins in my WebView.
webView = (WebView) findViewById(R.id.webviewplan);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
Any help would be appreciated. Thanks.
Edit: Found out that it is throwing a js error so is anyone out there able to display a YouTube embed preview in a WebView without flash, Or is this simply not possible?
Error:
TypeError: Result of expression 'a' [undefined] is not an object. --
From line 342 of http://s.ytimg.com/yt/jsbin/www-embed_core_module-vflcoqCCO.js
The YouTube JS is probably either shutting things down because it does not detect Flash or having a an error. If it is having an error you can find out of these by setting a custom WebChromeClient and override its onConsoleMessage method. Pump this to your LogCat (do a JS alert) and you will know about errors at least.
精彩评论