Cordova File Plugin从ioscaching中加载video源

我真的想从我的应用程序caching中加载video的来源。 在我的应用程序的本机部分,我将video保存到caching中文件夹内的文件夹。

/var/mobile/Containers/Data/Application/639797B4-1726-4350-91D7-2E212ACB974D/Library/Caches/.../.../clip.mov

所以我正在考虑使用cordova文件插件:

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/index.html#display-an-image-file-

老实说,我很困惑,我应该如何执行它。 我在应用程序的networking端几乎没有做任何事情。 只是一些基本的function,我不确定如何做到这一点,我应该在哪里做到这一点。 我知道这应该是在设备准备就绪之后。

所有我想要做的是读取文件,但它说我需要一个fileEntry对象,我想我需要创build一个临时或持久的文件。 (不确定哪个是合适的,因为我只是想临时使用这个文件,但是我把它保存到了文件caching文件系统中,所以我猜它是持久的?)我通常对我需要包含的内容感到困惑。

下面是我的准系统JS:

 var app = { // Application Constructor initialize: function() { this.bindEvents(); }, // Bind Event Listeners bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); ... //some button events ... }, // deviceready Event Handler onDeviceReady: function() { app.receivedEvent('deviceready'); // <--- }, // Update DOM on a Received Event receivedEvent: function(id) { var parentElement = document.getElementById(id); var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received'); listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); console.log('Received Event: ' + id); } }; app.initialize(); 

如果有人能指出我在正确的方向,将不胜感激。

谢谢。

在这里你可以用这个代码从你所说的path中取出这个文件,然后在Base64中把它放在一个variables中。 在这个基础上,你可以随时随地做任何事情。

 window.resolveLocalFileSystemURL(cordova.file.applicationStorageDirectory, function(dir) { console.log("got main dir",dir); dir.getFile("clip.mov", {create:false}, function(fileEntry) { console.log("got the file", fileEntry); fileEntry.file(function(file) { var reader = new FileReader(); reader.onloadend = function(e) { //In this e you have your file console.log(e); }; reader.readAsDataURL(file); }); }); }, function(err) { console.log(err); });