javascript - Cordova 3.6.3 File plugin - get local video file on android -



javascript - Cordova 3.6.3 File plugin - get local video file on android -

what i'd is

get uri of video file on device via cordovas javascript api set uri value of html5 video tag's src attribute.

the sec part shouldn’t problem. concerning first task, there lot of structured tutorials raymond camden's demonstrating how local files through javascript in cordova environment.

however, newest version of cordova, not work.

the video file

the video located either in assets/www/videos/testvid.webm or res/raw/testvid.webm in built apk file. both variations did not work.

the javascript mypath = cordova.file.applicationdirectory; // -> file:///android_asset/ //mypath += "www/videos/testvid.webm";

respectively

mypath = cordova.file.applicationstoragedirectory; // -> file:///data/data/com.example.mypackage/ //mypath += "raw/testvid.webm";

then:

window.resolvelocalfilesystemurl(mypath, gotfile, fail); function gotfile(entry){ if(entry.isdirectory) alert json.stringify(entry.getfile("testvid.webm")); } the permissions

in res/xml/config.xml access permissions added

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

the error {code:1} -> not_found_err

what doing wrong? how navigate file, or can 1 set found?

i figured out!

there bug in android version of cordova file plugin.

a workaround transferring file(s) assets directory of app file:///android_asset/ (cordova.file.applicationdirectory) working directory on phone file:///data/data/com.example.mypackage/files (cordova.file.datadirectory). set video's source url new file.

xmlhttprequest filetransfer trick.

var myfilename = "testvid.webm"; var myurl = cordova.file.applicationdirectory + "www/videos/" + myfilename; var filetransfer = new filetransfer(); var filepath = cordova.file.datadirectory + myfilename; filetransfer.download(encodeuri(myurl), 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 " + error.target); }), true, { headers: { authorization: "basic dgvzdhvzzxjuyw1lonrlc3rwyxnzd29yza==" } });

javascript android cordova video cordova-plugins

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -