Inline google drive video not playing in webview - android

My client website http://partidos.online has some embedded videos in his website which are shared from google drive but these videos are not playing in my webview. Hre is the URL for video http://partidos.online/video/47. I want to play this Inline video in this webview.
this is my Manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<application
android:hardwareAccelerated="true"
android:icon="#drawable/logo1"
android:theme="#style/AppTheme">
....
....
</application>
this my MainActivity.java
webView = (WebView) findViewById(R.id.webviewMain);
webView.getSettings().setMediaPlaybackRequiresUserGesture(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setPluginState (PluginState.ON);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setAppCachePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/cache");
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setDatabasePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/databases");
webView.loadUrl(URL);
webView.setWebViewClient(new WebViewClient();
webView.setWebChromeClient(new WebChromeClient(){});

You cannot play videos by WebView from your Google Drive. I suggest creating new YouTube channel and upload that video there. Then set the URL accordingly to URL of your video on YT.

Related

YouTube thumbnail won't load in webview

We have a WebView based android app which loads webpage consisting <a> tags linking to YouTube video.
The web app works fine in a browsers like Chrome for Android and loads thumbnail from YouTube as expected but within WebView the <a> tag won't load the thumbnail of YouTube video.
How can we force the WebView to behave similar to Chrome browser
Have tried setting clients like below, which didn't help
webview.setWebViewClient(new WebViewClient());
webview.setWebChromeClient(new WebChromeClient());
Even added hardware acceleration in AndroidManifest.xml but it didn't work either
android:hardwareAccelerated="true"
Note: JavaScript is also enabled.
Did you try to enable javascript in your webview?
You can enable it like this:
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

Problem when load html5 videos into webview

I have a problem when load html5 into webview.
My app in first build play video success but when i clear/kill app open again, webview not play video when click play.
Html5
<video src="url.mp4" controls poster="thumbnail.jpg" style="max-width: 100%;">Download video</video>
Source load webview
WebView webView = new WebView(context);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient());
String html = "<html><head><link rel='stylesheet' href='file:///android_asset/css/style.css'></head><body>"
+ htmlElement.getContent()
+ "</body></html>";
webView.loadDataWithBaseURL("file:///android_asset/", html, mimetype, encoding, "");
I research and try fix this issue but not success
https://stackoverflow.com/questions/3815090/webview-and-html5-video
https://issuetracker.google.com/issues/36935939 v.v..
Anyone has the same my problem? Thanks.
Try this :-
DashBoardFragment2.java :-
https://drive.google.com/file/d/1UREa7uGrQYcF-ABzPktBSjUcOPtytxSC/view?usp=sharing
dashboard.xml :-
https://drive.google.com/file/d/1LlgbdSe-9bgUU5lsGZUGOX3Tg7bnVpzH/view?usp=sharing

Youtube videos don't show up in WebView

I just added a webview to my app to load a simple article with a video on it and some text.
The text shows up as it should but it's as if the video is not even an invisible element.
WebView browser = (WebView) findViewById(R.id.webArticle);
browser.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
WebSettings settings = browser.getSettings();
settings.setBlockNetworkLoads(false);
settings.setBlockNetworkImage(false);
settings.setAllowContentAccess(true);
settings.setLoadsImagesAutomatically(true);
settings.setAllowFileAccess(true);
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
browser.loadUrl(url);
At first ,You need to add this
getSettings().setPluginsEnabled(true);
getSettings().setUserAgent(USER_MOBILE);
Then Add to the Application Manifest File (Below Permission):
android:hardwareAccelerated="true"
For demo code Play YouTube video in WebView
play youtube video in WebView

WebView is not loading HTML5 video in android

WebView wvVideo = (WebView) findViewById(R.id.wvVideo);
String ytVideo= "<html><body><iframe width='350' height='160' src='www.youtube.com/watch?v=yqNGzYsPN6M' frameborder='0' allowfullscreen></iframe></body></html>";
wvVideo.getSettings().setPluginsEnabled(true);
wvVideo.getSettings().setAllowFileAccess(true);
wvVideo.getSettings().setPluginState(PluginState.ON);
wvVideo.getSettings().setBuiltInZoomControls(true);
wvVideo.getSettings().setJavaScriptEnabled(true);
wvVideo.loadData(ytVideo, "text/html", "utf-8");
It just display thumbnail and when i click on that, its not playing. just display black screen. my API Target is 15 and i set all the required permissions for that but still not working.
Your settings seems fine.
As for me the following settings did the job on my project which play HTML5 videos. Try them
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true); // I think you will need this one
webview.getSettings().setPluginState(PluginState.ON);
webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);// no need I think
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.setInitialScale(1);
webview.setWebChromeClient(new WebChromeClient()); // dont forget this one
Add android:hardwareAccelerated="true" to your manifest file.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:hardwareAccelerated="true">

Opening youtube videos in a webview

I want to open youtube videos in a webview.
In a webview I go to the page of a video in youtube and when I try to play the video, it doesnot start. Is it possible to play youtube videos in a webview?
If it is not, how can I direct my application to open the video with native media player of the phone.
Try with this code:
myWebView = (WebView) findViewById( R.id.webview);
String playVideo= "<html><body>Youtube video .. <br> <iframe class=\"youtube-player\" type=\"text/html\" width=\"640\" height=\"385\" src=\"http://www.youtube.com/embed/bIPcobKMB94\" frameborder=\"0\"></body></html>";
myWebView.loadData(playVideo, "text/html", "utf-8");
And yes dont forget to add permission into your manifest:
<uses-permission android:name="android.permission.INTERNET"/>
I hope this will help you.

Categories

Resources