科尔多瓦3.6.3文件的插件 - 得到的Andr​​oid本地视频文件 [英] Cordova 3.6.3 File plugin - get local video file on android

查看:173
本文介绍了科尔多瓦3.6.3文件的插件 - 得到的Andr​​oid本地视频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的就是

  1. 获取设备上的视频文件的URI通过cordovas的JavaScript API
  2. 将URI作为一个HTML5 视频标签的的src 属性的值。
  1. get the URI of a video file on the device via cordovas javascript API
  2. set the URI as value of a HTML5 video tag's src attribute.

的第二部分不应该是一个问题。
关于第一个任务,有很多像的雷蒙德·卡姆登的演示了如何通过JavaScript获得在本地文件的科尔多瓦环境。

The second part shouldn’t be a problem.
Concerning the first task, there are a lot of good structured tutorials like Raymond Camden's demonstrating how to get local files through javascript in an cordova environment.

不过,与科尔多瓦的最新版本,我无法得到它的工作。

However, with the newest version of cordova, I could not get it to work.

视频或位于资产/ WWW /视频/ testvid.webm RES /生/ testvid.webm 在内置的apk文件。这两个变化没有工作。

The video is located either in assets/www/videos/testvid.webm or res/raw/testvid.webm in the built apk file. Both variations did not 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){
  if(entry.isDirectory)
    alert JSON.stringify(entry.getFile("testvid.webm"));
}

的权限

RES / XML / config.xml中访问权限添加

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

错误是{code:1} - > NOT_FOUND_ERR

The error is {code:1} -> NOT_FOUND_ERR

我是什么做错了吗?如何定位到该文件,或者一个在那里可以把它被发现的?

What am I doing wrong? How to navigate to the file, or where can one put it to be found?

推荐答案

我想它了!

有一个在科尔多瓦文件插件的Andr​​oid版本一个错误

There is a bug in the android version of the cordova file plugin.

一个解决方法是从应用程序本身文件的资产目录传输文件(S):/// android_asset / (cordova.file.applicationDirectory),以工作///data/data/com.example.MyPackage/files (cordova.file.dataDirectory):像文件在手机上目录。然后设置视频的来源网址到新的文件。

A workaround is transferring the file(s) from the assets directory of the app itself file:///android_asset/ (cordova.file.applicationDirectory) to a working directory on the phone like file:///data/data/com.example.MyPackage/files (cordova.file.dataDirectory). Then set the video's source URL to this new file.

XMLHtt prequest 以及<一个href="http://stackoverflow.com/questions/24300176/phonegap-build-download-image-in-one-of-the-folders-of-your-app">FileTransfer将这样的伎俩。

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

这篇关于科尔多瓦3.6.3文件的插件 - 得到的Andr​​oid本地视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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