cordova-plugin-file icon indicating copy to clipboard operation
cordova-plugin-file copied to clipboard

Read the video file on android

Open idreamin opened this issue 5 years ago • 5 comments

the fullpath is file:///storage/emulated/0/DCIM/Camera/VID_20190523_184820.mp4 How should I use cordova-plugin-file to read it ?

Here's my code: I want to get the 'reader.result', thank you very much !

window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function (dirEntry) {
dirEntry.getFile(_this.filename, { create: true, exclusive: false }, function (fileEntry) {
    fileEntry.file(function (file) {
    var reader = new FileReader()
     reader.onloadend = function () {
     console.log('Successful file read: ' + reader.result)
   }
   })
})

idreamin avatar May 24 '19 08:05 idreamin

Maybe you should read the docs. Eventually you don't need to read the video file. You can use file-urls in your html to embed the video.

GitToTheHub avatar Jun 23 '19 11:06 GitToTheHub

@GitToTheHub Please consider your language, "Maybe you should read the docs." is not an appropriate way to answer to someone asking for help. If the answer is in the documentation, provide a link to the correct headline and just tell the user that their question is answered there.

janpio avatar Jun 26 '19 10:06 janpio

It was only a hint, that he in general should read the docs of this plugin first before asking.. Here a link: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#display-an-image-file

In Android you must allow content:-File Links in your Content Security Police, so the image/video links can be displayed if you choose from the Photo Library:

<meta http-equiv="Content-Security-Policy" content="
    default-src * data: gap: content: https://ssl.gstatic.com 'unsafe-eval';
    style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
    script-src 'self' 'unsafe-inline' 'unsafe-eval' *;
    connect-src 'self' 'unsafe-inline' 'unsafe-eval' blob: ws: *;">

GitToTheHub avatar Jul 03 '19 19:07 GitToTheHub

@GitToTheHub @janpio
I followed the steps, unable to read the video file! My File entry object is -

 {"name":"20191107_170431.mp4",
"localURL":"cdvfile://localhost/root/storage/07ED-F818/DCIM/Camera/20191107_170431.mp4",
"type":"video/mp4","lastModified":1573183466000,
"lastModifiedDate":1573183466000,
"size":15140263,"start":0,"end":15140263}

And I am trying to embed it in my video tag by setting the source by of the file as - fileEntry.localURL.

Any help will be appreciated. I have tried other solutions such as normalizeUrl and replacing the "file://" but couldn't get it to work.

neerajsaxena0711 avatar Nov 28 '19 11:11 neerajsaxena0711

Maybe you must allow cdvfile: in the default-src of your Content Security Policy. normalizeUrl is from Ionic and works not with cdvfile-urls. And it's only necessary for iOS.

GitToTheHub avatar Dec 07 '19 11:12 GitToTheHub