How To Play Dailymotion Video Inside A Webview In Android
I need to play a video from daylimotion in an Android WebView, I've tried with several approuches but haven't found a working solution. The video I need to play is like the one in
Solution 1:
Dailymotion provides a WebView based SDK that includes all the tricks required for you to play the video easily :
The README provides an easy example of integration
Solution 2:
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebViewwv= (WebView) findViewById(R.id.webview1);
WebSettingswebSettings= wv.getSettings();
webSettings.setJavaScriptEnabled(true);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setAppCacheEnabled(true);
wv.getSettings().setBuiltInZoomControls(true);
wv.getSettings().setSaveFormData(true);
wv.setWebChromeClient(newWebChromeClient());
wv.setWebViewClient(newCallback());
wv.loadUrl("http://www.dailymotion.com/video/x1iepl4_blackfish-full-documentary_animals");
}
privateclassCallbackextendsWebViewClient {
@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return (false);
}
}
Solution 3:
Just solved the problem. The solution is as follows:
WebSettingswebSettings=this.wvVideo.getSettings();
finalStringmimeType="text/html";
finalStringencoding="UTF-8";
String html;
webSettings.setJavaScriptEnabled(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setUserAgentString(null);
// Taken from the urlStringvideoId="x1iepl4_blackfish-full-documentary_animals";
html = this.getHTMLDailyMotion(videoId);
this.wvVideo.loadDataWithBaseURL("", html, mimeType, encoding, "");
Then the method to build the HTML is as follows:
privateString getHTMLDailyMotion(String videoId) {
String html ="<iframe class=\"youtube-player\" "+"style=\"border: 0; width: 100%; height: 95%;"+"padding:0px; margin:0px\" "+"id=\"ytplayer\" type=\"text/html\" "+"src=\"http://www.dailymotion.com/embed/video/"+ videoId
+"?fs=0\" frameborder=\"0\" "+"allowfullscreen autobuffer "+"controls onclick=\"this.play()\">\n"+"</iframe>\n";
return html;
}
This shows the video on full screen.
Post a Comment for "How To Play Dailymotion Video Inside A Webview In Android"