Cordova 3.6.3 File Plugin - get local video file on android

What I would like to do is

  • get the URI of a video file on a device via the cordovas javascript API
  • set URI as attribute value video


    for HTML5 video


The second part shouldn't be a problem.
Regarding the first task, there are many good structured tutorials, such as Raymond Camden , demonstrating how to get local files via javascript in cordova .

However, with the newest version of cordova, I couldn't get it to work.

Video file

The video is either in assets/www/videos/testvid.webm

or res/raw/testvid.webm

in the embedded apk file. Both options don't work.


myPath = cordova.file.applicationDirectory; // -> file:///android_asset/
//myPath += "www/videos/testvid.webm";



myPath = cordova.file.applicationStorageDirectory; // -> file:///data/data/com.example.MyPackage/
//myPath += "raw/testvid.webm";



window.resolveLocalFileSystemURL(myPath, gotFile, fail);
function gotFile(entry){
    alert JSON.stringify(entry.getFile("testvid.webm"));



The res/xml/config.xml

added access permission

<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,root" />


Error: {code: 1} → NOT_FOUND_ERR

What am I doing wrong? How do I navigate to the file or where can I find it?


source to share

1 answer

I understood that!

There is a file in the android version of the cord file .

A workaround is to move the file (s) from the resource directory of the application itself file:///android_asset/

(cordova.file.applicationDirectory) to the working directory on the phone, for example file:///data/data/com.example.MyPackage/files

(cordova.file.dataDirectory). Then set the video source URL to this new file.

XMLHttpRequest as well as FileTransfer will do the trick.

var myFilename = "testvid.webm";
var myUrl = cordova.file.applicationDirectory + "www/videos/" + myFilename;
var fileTransfer = new FileTransfer();
var filePath = cordova.file.dataDirectory + myFilename;, filePath, (function(entry) {
  res = "download complete:\n"
  res += "fullPath: " + entry.fullPath + "\n"
  res += "localURL: " + entry.localURL + "\n"
  alert(res += "nativeURL: " + entry.nativeURL + "\n")
  var vid = document.getElementById("someID");
  vid.src = entry.nativeURL;
  vid.loop = true;
}), (function(error) {
  alert("Video download error: source " + error.source);
  alert("Video download error: target " +;
}), true, {
  headers: {
    Authorization: "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="




All Articles