I need to play a youtube video in webview, the link to the video is present in my tag. But when I run my application, only a pic(thumbnail) comes in the place with play icon on it, and after clicking on it, it shows a black screen with a seekbar on it at 00:00 time, and loading symbol on it, but then nothing happens or is shown. It than remains there all day.
I am using Emulator with 4.4 Android.
My code is a follows:-
WebView content = (WebView)findViewById(R.id.webView1);
String html="<html><body>Some text goes here<br>"
+ "<iframe src=\"//www.youtube.com/embed/eu9kMIeS0wQ?rel=0\" height=\"360\" width=\"640\" allowfullscreen=\"\" frameborder=\"0\"/></iframe></body></html>";
content.getSettings().setPluginState(PluginState.ON_DEMAND);
content.getSettings().setJavaScriptEnabled(true);
content.getSettings().setAllowFileAccess(true);
content.setWebChromeClient(new WebChromeClient());
content.setWebViewClient(new WebViewClient());
content.loadDataWithBaseURL("SomeStringForBaseURL", html, "text/html", "UTF-8", "");
I had also included the
android:hardwareAccelerated="true"> In the manifest.
DO I need to add any API's for Youtube or for any other thing. or what sort of mistake I am commencing? Any help will be appreciated. Thanks In Advance.
Well everything is fine, and the video is running nice and fast. Well, the emulator requires flash player to be installed, whereas this code makes videos playable on android devices. If anyone needs the source code, they can use the one above for running the videos in WebView via tag on android.