Am looking for the way to play video inside my android browser locally. There may be two or more video's in a local page (like facebook contains video's).
Can anyone please help me out..
Without actually reading about the specifics of the Android built in browser I would safely say, you can't. Well, if you run a local html file it might work, but if you intend to have an external page from which you can play local videos it shouldn't work. I say shouldn't because in the early days of browsers some of them actually did give you access to the local file system. Javascript for example could use file://, something I used myself for image previewing before upload. But this was a major security concern and all modern browsers prevent this.
The difference is if you run a local file or a file on your own local web server. Since then, your local file system is actually part of the web servers file system and the web server can serve your local files.
Related
I have below iframe in one of the page in my website.
<iframe src="http://www.pdf995.com/samples/pdf.pdf" id="iframe1">
But when I open same page in android mobiles chrome browser it is automatically triggering download of file which is mentioned in the iframe. How can I prevent auto triggering of download in mobile devices?
You can use this format:
https://docs.google.com/viewerng/viewer?url=http://yourfile.pdf
Just replace http://yourfile.pdf with the link you use.
Ideally, it is important to think on the availability to use the convert/viewer in offline mode!
Why and Because...
If you use an iframe for a stored document on your server and you would made an webapp, you will must play over HTTPS/SSL. (Offline is over https).
It is not sure that the PDF viewer provides a secure url (1), you will probably problems with CORS and others with the « Same origine » to embed the iframe src (2), and finally, it service must delivers online and offline ! So it recommended to embed in application cache all the resources needed to convert the PDF in canvas.
An all in one solution is strongly recommended I think.
Using PDF.js and its worker with a runtime script is a good way...
The core part of my application is load PDF online and user have access to download it as per their given rights.
The problem I am facing is that I want to load pdf online. After many research I have found that,
There are likely two ways to show pdf online in android:
1) In Web view by loading simple hosted URL
2) By google doc.
But in our case, if we use way (1), the mobile web view does not redirect hosted url of PDF.
And if we use way (2), then there are certain limitations of the google docs regarding the file sizes. (Small pdf it will load like 5 to 10 with size of 1MB)
But after loading PDF with the size of 2 or 3 MB it's also giving me error as "No PREVIEW AVAILABLE" and its continuously giving me this error opening different urls.
So it seems there is still no easy solution for viewing a pdf from url (online without downloading pdf).
The other way to open pdf online is that we can open it in any other third party applications like browser, adobe pdf reader or any kind of pdf viewer application available in the device.
Cons: If we open pdf in browser then it will get downloaded automatically and if we open it in any third party application then they have options to download the pdf.
Please give me some solution to read the PDF online.
And if there are any paid pdf SDK availble which gives functionality of loading pdf online from URL, then please provide information of that too.
Please also suggest me some pdf viewer library for displaying pdf online.
I have used many of the library, but it increases my application's size to 8 to 10 MB.
Thanks in advance.
The suggested primary solution,
Download the file, store it in the app specific folder so users don't have access. For viewers who don't have access rights to download it, you will delete the file as they leave the view. For viewers who have access rights to download it, they will be given an option to copy the file to their SD card (an accessible location) and then you will delete the original file as they leave the view.
For storing in app specific directory to restrict user access,
http://www.grokkingandroid.com/how-to-correctly-store-app-specific-files-in-android/
Also use a library to view the pdf(MUCH SIMPLER), choose an appropriate one from here
https://android-arsenal.com/search?q=pdf
Alternate solution,
If security is a major concern, you can encrypt the pdf file and store it on the server. And decrypt the file when you download it to the device.
For added security, don't store the file as pdf, just store it as a file. Download it as a file. Set type as pdf when you want to access it.
Conclusion,
Data wise, Even if you load it online, the device will consume almost same data as downloading the pdf. (Infact for viewing something online, your device downloads the data and stores it in the cache and you can view it)
Security wise, only a rooted phone will be able to access the file but that too for as long as you have decided to store it.
I suggest you check out PDF.js, a Javascript library from Mozilla to render PDF's in a browser. You can adapt this into a WebView easily, and display PDF's without downloading them.
Here is an open source app which does something similar to what you're looking for
I'm building a thin native wrapper for a web application on Android. I want to keep my HTML & Javascript on the web, as it'll reduce the frequency with which the App needs to be updated.
However, I want to take advantage of SD card storage for storing videos -- my application has several videos that are likely to be played multiple times, so I'd rather download them and play them from the local copy.
What I have already done successfully:
Written a #JavascriptInterface that gets called when the page is being viewed through the app that downloads the videos and saves them to getExternalFilesDir(Environment.DIRECTORY_MOVIES).getAbsolutePath()
Written a script that replaces the src of the html element with a file:// Url once the download is complete.
The Problem
I'm getting a javascript error in the console:
"Not allowed to load local resource: file:///storage/emulated/0/Android/data/path/to/video.mp4"
I presume this is because I have a video element
<video src="file:///......."/>
Which is being served by a different (non local) domain, so webview's security is saying no.
There are several WebSettings methods like setAllowFileAccess(), but they specifically state this only enables JavaScript access to files and not HTML elements such as <img> or (in this case) <video>
Is there any way around this?
If not, what should my alternative approach be?
EDIT:
Could I just use the built in browser cache for this?
my android browser doesn't seem to cache a html5 video with tag, since every time the page reloads, the flux increases.
so i changed the .mp4 file to .jpg on the server side, hoping my browser caches the fake .jpg.
problem is, how can I use the cached jpg and change it back to .mp4 and add it to the src?
searched loads of web pages, couldn't find an answer to access the cached file. some said it's security issues that javascript can't access file system.
so any ideas that i can access the cached file or cache the mp4 on my android phone?
Thank you!!
I searched through a lot of questions on SO but I can't find the answer, that's why I ask the following question:
An Android app should be able to play an encrypted video file (stored on the SD card and retrieved from a webserver).
The file has to be stored on the SD card so that the app can play the video file without having an active internet connection.
Because the video files may not be copied, the plan is to encrypt them server side when uploading the files to a webserver.
What is the best option?
1) I have seen suggestions for running a local webserver which decrypts the file (and how to do this?)
2) or should we decrypt the file, save it as a temporary file and set this temporary file as the source for the videoplayer?
3) something completely different?
You are trying to implement a DRM scheme, and a naive one at that. Look into DRM schemes and report back if you cannot implement the impossible. All you can hope for is obfuscation, and there are plenty of ways of doing that (none of them are secure of course).
What you need is DRM. Digital Rights Management (DRM) controls the access to your digital content such as video. Firstly, you need to encrypt the video with an encryption video like AES-128. Then with the use of DRM play in exoplayer. Exoplayer has DRM support. you can check here. https://exoplayer.dev/drm.html
You will expose the user to a waiting time if you choose to decrypt a entire big video beforehand. As of the security, you can guess it's a poor idea to have the contents in clear in a file, even temporary. The local webserver is a better choice because it's a streaming method, so without file storage. There is no class for an http server in the SDK, you have to implement your own one, otherwise look for an existing library similar to LocalSingleHttpServer.