Cordova File Plugin可以从ios缓存中加载视频源 [英] Cordova File Plugin to load video source from ios cache

查看:188
本文介绍了Cordova File Plugin可以从ios缓存中加载视频源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很想从我的应用程序缓存中加载视频源.在我的应用程序的本机部分中,我将视频保存到缓存中文件夹中的文件夹中.

I really want to load the source of a video from my applications cache. In the native part of my application I'm saving a video to a folder within a folder within caches.

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

所以我一直在研究使用cordova文件插件:

So I was looking into using the cordova file plugin:

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

老实说,我对应该如何实现它感到困惑.在应用程序的Web端,我几乎什么也没做.仅有一些基本功能,我不确定如何执行此操作以及应该在何处执行.我知道应该在设备准备就绪后才能出现.

and honestly I'm so confused as to how I'm supposed to implement it. I've done almost nothing on the web side of the application. Just a few basic functions and I'm sort of unsure as to how to do this and where I am supposed to do it. I understand that it's supposed to come after the device is ready.

我要做的就是读取文件,但是它说我需要一个fileEntry对象,我认为我需要为其创建一个临时文件或持久性文件. (不确定哪个是合适的,因为我只想临时使​​用文件,但是我将其保存到文件缓存文件系统中,所以我猜它是持久的?)我只是对我需要包含的内容感到困惑.

all I want to do is read the file but it says I need a fileEntry object for which I think I need to create a temporary or persistant file. (Not sure which is appropriate because I only want to use the file temporarily but I am saving it into the file caches file system so I guess it's persistant?) I'm just generally confused about what I need to include.

下面是我的准系统JS:

Below is my barebones 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();

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

if anybody could point me in the right direction it would be greatly appreciated.

谢谢.

推荐答案

在这里,使用此代码,您可以从所说的路径获取文件,并将其保存在Base64中的变量中.在此基础上,您可以随心所欲地进行操作.

Here you have, with this code you can take the file from the path you said, and have it in Base64 in a variable. In base of this you can do wherever you want with it.

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);
        });

这篇关于Cordova File Plugin可以从ios缓存中加载视频源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆