I'm trying to embed a Youtube player into my Android app using a WebView. I've followed several examples (including http://fancifulandroid.blogspot.com.es/2013/01/play-youtube-video-in-webview-without.html and YouTube Video not playing in WebView - Android) but cannot get it to work. When I load my activity, the youtube video player shows up with the correct preview image, but when I attempt to play it, the loading icon cycles continuously, and I get the following error in my logs:
12-07 19:23:18.484: D/HTML5VideoInline(26166): HTML5VideoInline created
12-07 19:23:18.484: V/MediaPlayer-JNI(26166): native_setup
12-07 19:23:18.484: V/MediaPlayer(26166): constructor
12-07 19:23:18.484: V/MediaPlayer(26166): setListener
12-07 19:23:18.484: V/MediaPlayer(26166): setVideoSurfaceTexture
12-07 19:23:18.484: V/MediaPlayer-JNI(26166): reset
12-07 19:23:18.484: V/MediaPlayer(26166): reset
12-07 19:23:18.484: I/MediaPlayer(26166): path is null
12-07 19:23:18.484: D/MediaPlayer(26166): Couldn't open file on client side, trying server side
12-07 19:23:18.494: V/MediaPlayer(26166): setVideoSurfaceTexture
12-07 19:23:18.494: V/MediaPlayer(26166): prepareAsync
12-07 19:23:18.754: E/Web Console(26166): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1:566
12-07 19:23:18.789: E/Web Console(26166): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1:566
12-07 19:23:18.849: E/Web Console(26166): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1:566
12-07 19:23:18.879: E/Web Console(26166): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1:566
12-07 19:23:18.929: E/Web Console(26166): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1:566
12-07 19:23:18.994: E/Web Console(26166): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1:566
12-07 19:23:19.029: E/Web Console(26166): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1:566
12-07 19:23:19.114: E/Web Console(26166): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1:566
12-07 19:23:19.134: E/Web Console(26166): Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1:566
Here is my code:
if(mediaURL.toLowerCase().contains("youtube")){
Log.d(TAG, "adding youtube video");
final String mimeType = "text/html";
final String encoding = "UTF-8";
String youtube_url = "<iframe class=\"youtube-player\" "
+ "style=\"border: 0; width: 100%; height: 95%;"
+ "padding:0px; margin:0px\" "
+ "id=\"ytplayer\" type=\"text/html\" "
+ "src=\"" + mediaURL
+ "?fs=0\" frameborder=\"0\" " + "allowfullscreen autobuffer "
+ "controls onclick=\"this.play()\">\n" + "</iframe>\n";
Log.d(TAG, "youtube_url: " + youtube_url);
final WebView video = new WebView(MediaPreview.this);
video.setWebChromeClient(new WebChromeClient() {
});
video.loadDataWithBaseURL("", youtube_url, mimeType, encoding, "");
video.getSettings().setJavaScriptEnabled(true);
video.getSettings().setPluginState(PluginState.ON);
video.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
mediaHolder.addView(video);
}
I've also set android:hardwareAccelerated="true" in my AndroidManifest.xml and confirmed that the embed url link works in my browser. How can I solve this problem?