How to stream swf file in android WebView - android

My app is supporting min api level 15 and I want to show a list which streams video from remote servers and video can be of any file format, thus I am considering the WebView as best choice but I am unable to stream swf file in WebView. And also for other files the WebView is showing jumping effect in ListView after loading the Videos.

Can you show us what have you already tried? Some code would be useful in order to understand what could be the problem.
Until then, you could try the following:
mWebView = (WebView) findViewById(R.id.webView1);
mWebView.getSettings().setJavaScriptEnabled(true);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO) {
mWebView.getSettings().setPluginsEnabled(true);
}
else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2){
webview.getSettings().setPluginState(WebSettings.PluginState.ON);
}
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.setBackgroundColor(Color.parseColor("#000000"));
mWebView.loadUrl("http://your_file_location.swf");

Related

Mozilla PDF extremely slow on Samsung Devices

I have an application in which I am using Mozilla PDF for viewing PDFs.
Mozilla PDF uses web view to load PDFs.
The PDF files are large, and are all images actually.
The application works fine, but the PDF loads extremely slow on all Samsung devices. The application works fine on other devices, but is so slow on Samsung that it's really useless.
I have the following settings for the web view:
settings.setJavaScriptEnabled(true);
settings.setRenderPriority(RenderPriority.HIGH);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
I also have set a WebChromeClient.
Does anyone knows why am I facing this issue? And only on Samsung devices?
Any workarounds? Any help would be greatly appreciated.
Here’s a WebView setup to display PDFs using PDF.js. It works fine on all devices (that are running at least API 19), including old tiny about-to-die Samsungs.
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setSupportMultipleWindows(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
{
webView.getSettings().setAllowFileAccessFromFileURLs(true);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
{
webView.getSettings().setMediaPlaybackRequiresUserGesture(true);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
}
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAllowContentAccess(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
// should enable pinch to zoom....
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
String webViewUrl;
try
{
/*
Try encoding the PDF file URL. I think i’ve read that this helps with
load/rendering speed?
*/
webViewUrl = "file:///android_asset/pdfjs/web/viewer.html?file=" + URLEncoder
.encode(pdfUri.toString(), "UTF-8");
}
catch (UnsupportedEncodingException e)
{
// It works without encoding it (at least in my case) so just display it with the string as is.
Log.e("Error encoding PDF file URL, will display without encoding.", e);
webViewUrl = "file:///android_asset/pdfjs/web/viewer.html?file=" + pdfUri.toString();
}
webView.loadUrl(webViewUrl);
Not sure if this will help, but thought I’d post a full WebView setup to support PDF.js, which I’ve never run into speed issues with. Good luck.
Note: Might also be a good idea to turn hardware acceleration on in your application’s manifest. This is only available on API 14 and above. By now this shouldn’t be an issue (if it is, my heart goes out to you).
<application
android:name="com.pdfjs.webview.app.McAwesome"
//...
android:hardwareAccelerated="true">
</application>

how to load pdf file in a webview from assets folder

I ahve a webview in my layout screen. I need to display a PDF file in that webview from my assets folder. I tried below code. While running app displays zoom in and out controls with a blank page(our PDF file is kind of large.is it due to that?).
webView = (WebView) findViewById(R.id.webView1);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN) //required for running javascript on android 4.1 or later
{
settings.setAllowFileAccessFromFileURLs(true);
settings.setAllowUniversalAccessFromFileURLs(true);
}
settings.setBuiltInZoomControls(true);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("file:///android_asset/test.pdf");
I dont want to use external apps to read my PDF. is it possible?then how?
You can use pdf.js from Mozilla to display a PDF in a webview inside an Android application.
Here is the solution...
https://stackoverflow.com/a/21383356/2260073
This question is answered already . For the details refer the following links.
How to read pdf in my android application?.
One more is
stackoverflow.com/questions/10299839/how-to-read-pdf-in-my-android-application/10352422#10352422
After searching a lot about this i came up with my own kind of solution
I used this website to convert my PDF to DOCX and then DOCX to HTML using online converters and then used the following code to load the HTML in my Webview.
String htmlString = "<p>YOUR HTML CODE</p>";
webView.loadData(htmlString, "text/html", "UTF-8");
Hope this helps!

How to open a PDF file from server in android

I have a requirement where there is a URL = "http://www.example/Open.pdf"
Now from my android application I want to open this PDF file directly in the default PDF viewer.
The moment I click on this link on the webpage, user should be presented with a default PDF viewer opened with this document.
Note: This file should not be stored on the SD card.
How do I proceed for this implementation?
We can open PDF file in the webview without caching it. Write below code in "onCreate" method .
Working code :
String url = "http://www.example.com/abc.pdf";
final String googleDocsUrl = "http://docs.google.com/viewer?url=";
WebView mWebView=new WebView(this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return false; // then it is not handled by default action
}
});
mWebView.loadUrl((googleDocsUrl + url));
setContentView(mWebView);
What happens here is you open the PDF using Google Docs. Best Advantage of using above method is the lazy loading of PDF. Does not matter how heavy the PDF is. Google Docs takes care of it.
You can view the pdf in the WebView using googleDocs.
WebView webView = (WebView) findViewById(R.id.my_webview);
webView.setWebViewClient(new MyWebViewClient());
webView.addView(webView.getZoomControls());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf");
There is no way you can open a default PDF view from your application.
If your file is on the server and you want to open it without downloading then this might also pose a greater security concern. If external applications like default adobe reader can access the content on your server, then this is breaking the security framework altogether.
So, best option would be to launch a new instance of browser or webview and show the PDF document in google docs to the user.
This way user can read the document and get back to the recent state of the application as well.
You can view the pdf in the WebView using googleDocs.
WebView webView = (WebView) findViewById(R.id.my_webview);
webView.setWebViewClient(new MyWebViewClient());
webView.addView(webView.getZoomControls());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf");
do you have the others solution besides view pdf file using http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf

Cannot play video inside WebView using iframe tag?

I am using the following data to display in a WebView. These are the HTML tags along with
the iframe which is referring to a video.
Now the problem is when I click on it, it shows the play button but cannot play the video.
Can I play this video inside WebView or not?
<p></p><P> because of Jon’s pro-growth, business-friendly policies,&nbsp;Utah's economy expanded at more than triple the national rate and was named the best state for business by&nbsp;<EM>Forbes.</em><BR /><BR /><IFRAME height=241 src="http://player.vimeo.com/video/25349114" frameBorder=0 width=425></iframe></p><br />
<P>America needs a dose of the same medicine. Today, our nation has the second highest corporate tax rate in the developed world. We have convoluted and confusing regulations.
<!--break--><!--break--><p></p>
when I try to run this url in the android browser it opens videoview and plays that file perfectly but why not in iframe?
http://player.vimeo.com/video/25349114
The key thing is to enable browser plugins.
// how to enable the webview plugin changed in API 8
if (Build.VERSION.SDK_INT < 8) {
mWebView.getSettings().setPluginsEnabled(true);
} else {
mWebView.getSettings().setPluginState(PluginState.ON);
}
Also worth checking flash player is installed
WebView wv;
wv = (WebView) findViewById(R.id.mywebview);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setBuiltInZoomControls(true);
wv.getSettings().setPluginsEnabled(true);
Use this code to load your video and also update the flashplayer of your device...

Web view Video streaming in android?

I use the following code to play the Video from remote server,
WebView webView = (WebView) findViewById(R.id.webview);
webView.loadUrl("http://commonsware.com/misc/test2.3gp");
its not playing the Video, while if i put the link in browser it will working fine.What mistake i made i don`t know.Even i also put internet access permission in manifest file.
Thanks.
Try this:
wv = (WebView)findViewById(R.id.webview);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginsEnabled(true);
wv.loadUrl("http://commonsware.com/misc/test2.3gp");

Categories

Resources