Android Webview Video not working - android

I build a little Android library in Eclipse, that open new Activity, put inside it WebView and load into WebView html page with video. I'm using WebView like:
webView.setWebChromeClient(new WebChromeClient() {
#Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100) {
showContentOrLoadingIndicator(true);
}
}
});
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
and
webView.loadUrl("http://www.example.com/mobile/player/" + VeediUtils.GAME_ID + "/" + ((JSONObject)VeediUtils.LEVELS.get(gameLevel - 1)).getInt("unique_id") + ".html" + ((debugState == 0) ? ("") : ("?debug=veedi")));
Next step, I had built new project, added my first project like a Android dependency, and all works ok, how it should. But when I gave my library to other developer (I don't have access to his code) and he added it like Android dependency to his project, he found an issue: there is he hear sound but instead of video he see black screen. So here the question: what it can be in his application, that break my video in WebView? Thanks.

The webview does not properly support HTML5 video.
See here for a library for proper video support.
If the video is in flash format, it will not work on android 4.4 and up. Otherwise, the user needs to have flashplayer installed, and you need to enable plugins in your webview.

Related

Display a pdf with dynamic generating url in WebView / Google Docs

so I just started with Android programming and I am trying to make a little app using WebView. There is a url that redirects you to a pdf, I know WebView does not render pdf. So I want to use intent and display the pdf in Google Docs. However, the pdf address is randomly generated so I cant link it with
WebView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdfURL);
How can I send an intent to Google Docs without using the exact pdf address?
I don't know what "randomly generated" means.
But the first thing that comes to my mind is to set a WebViewClient and override shouldOverrideUrlLoading:
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.endsWith(".pdf") == true) {
view.loadUrl("http://docs.google.com/gview?embedded=true&url=" + url);
return true;
}
return false;
}
});
Some more info in this thread.

How to load large pdf file in Android into my webview

i am unable to load a large pdf file (having 900 page) into my
webview in my android app, i try this code and working well on any
other pdf, but when i try to open a large one it display: No Preview
Available.
wvReport.getSettings().setJavaScriptEnabled(true);
wvReport.getSettings().setAllowFileAccess(true);
wvReport.getSettings().setAllowContentAccess(true);
wvReport.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
Toast.makeText(ReportsViewActivity.this, "Oh no! " , Toast.LENGTH_SHORT).show();
}
});
wvReport.setWebChromeClient(new WebChromeClient() {
#Override
public void onProgressChanged(WebView view, int progress) {
if (progress == 100) {
progressBar.setVisibility(View.INVISIBLE);
progressBar.setProgress(0);
} else {
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(progress);
}
}
#Override
public void onReceivedTitle(WebView view, String title) {
}
});
wvReport.loadUrl("http://docs.google.com/viewer?url="+url);
Try this code:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
and it's working, so if the pdf is too large , will be downloaded and opened via pdf viewer.
You don't. Webviews display html. The fact that this works at all is by a hack- google will convert simple pdfs into html. It doesn't seem like they support anything that big. Even if they did, I would expect loading a 900 page pdf converted to html would be so large I highly doubt you'd be able to load it without going OOM. Use an apropriate pdf library, make a real pdf rendering view, and make sure not to render more of the pdf at a time than you need (or else you'll go OOM anyway). In other words, don't rely on hacky solutions you never should have relied on in the first place.
You should try alternatives like PDF.js running locally in your device, instead of a service like Google Docs preview.
Put it in your assets folder and tweak the example:
wv.loadUrl("file:///android_asset/web/viewer.html");
Also, as #gabe-sechan mentions, you can have Out Of Memory situations. An alternative to try is a native viewer like AndroidPdfViewer.

Android WebView Not Loading Correctly

I'm having a few issues regarding the WebViewClient on Android.
The site works perfectly on any mobile browser. Including the ChromeViewClient that I have set for debugging purposes.
And the website that I am loading does not have any issues or errors when using any other mobile browser. Using Chrome's inspector and selecting a device, using as mentioned the native Android browser and also tested on an iOS WebView Component to make sure.
The WebViewClient renders "parts" of the website. Images on one page and not the other, buttons that can not be clicked, a slider that does not work, etc. The website that I am loading is very JavaScript and HTML5 intensive. I am completely out of ideas of how to debug this issue further, are there certain JavaScript libraries that the WebViewClient can't load properly? Is there any other method you would recommend I implement while trying to debug this issue? Or am I missing some really small thing that will make me hit my head against the table?
These are the JS files we are using on the website:
bootstrap.min.js;
jquery.min.js;
swiper.jquery.min.js;
slideout.min.js;
owl.carousel.min.js.
Code for the WebView:
this.webview = (WebView)findViewById(R.id.webView);
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
firstLoad = true;
return true;
}
// when the page is finished loading
public void onPageFinished(WebView view, String url){}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
Toast.makeText(getBaseContext(), "Could Not load. " + description, Toast.LENGTH_SHORT).show();
alertDialog.setTitle("Error");
alertDialog.setMessage(description);
alertDialog.setButton("OK", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
return;
}
});
alertDialog.show();
}
});
webview.loadUrl("mywebsite.com");
I got it working by setDomStorageEnabled(true);
You need to set this when using local storage.

Android WebView loading part of a website

Some websites have comments portion and many other unnecessary portions. I want to just display the main article excluding the other portions in my custom Android WebView.
I have tried the example from Display a part of the webpage on the webview android
But it still shows the full website.
There is also the loaddatawithbaseurl class in Android but it is not working too as you can't specify till which portion of a website to show using this class.
Is there any other way to do this?
Here it is with some changes...
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url)
{
String javaScript = "javascript: var form = document.getElementsByClassName('university_corner');"
+ "var body = document.getElementsByTagName('div');"
+ "body[0].innerHTML = form[0].innerHTML";
webView.loadUrl(javaScript);
}
});
webView.loadUrl(url);

Force WebView Video Controls

I have an Android app that plays embedded html5 videos. The html code that I receive does not include the "controls" attribute in the video tag. I'm wondering if there is a way to force the controls to be shown while the video is in the WebView. In 2.3 you can use WebChromeClient to display the full video. However in 4.x it appears you need to show the full controls first in order to take advantage of this class.
You could add the controls attribute:
webView.getSettings().setJavascriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView webView, String url) {
super.onPageFinished(webView, url);
webView.loadUrl(
"javascript:(function() {" +
"var video = document.getElementsByTagName('video')[0];" +
"video.controls = 'controls';" +
"})()"
);
}
});

Categories

Resources