使用 Phonegap 在 Android 上捕获后使用 FileReader 读取视频文件
我面临着一个问题,在phonegap应用程序中捕获视频本应是一个简单的任务。我想做的是启动录像机,捕获视频文件,取回 mediaFile,然后从中提取文件路径并使用 fileReader 读取它。我需要该文件采用二进制 base64 格式,因此我使用 readAsDataURL 来读取它。
但发生的情况如下。视频捕获正确,文件路径读取正确。文件读取器启动。然后应用程序崩溃,并且没有弹出成功警报。当我尝试读取 SD 卡上的任何文件(无论视频如何)时,就会发生这种情况。
这是代码片段:
function captureSuccess(mediaFiles) //video captured successfully
{
var i=0;
alert(mediaFiles[i].fullPath);
alert(mediaFiles[i].size);
fileReader = new FileReader();
fileReader.onerror = function () {
alert("failed");
}
fileReader.onload = function (evt) {
alert(evt.target.result);
}
fileReader.readAsDataURL(mediaFiles[i].fullPath);
}
I am facing a problem in what should have been a simple task of capturing video inside phonegap app. What I am trying to do is to start video recorder, capture a video file, get back the mediaFile and then extract the file path from it and read it using fileReader. I need the file to be in binary base64 so I am using readAsDataURL to read it.
What happens though is as follow. The video is captured correctly, the file path is read correctly. Filereader gets initiated. Then the app crash without the success alert poping up. This happened when I tried to read any file on the sdCard regardless of the video.
Here is the code snippet:
function captureSuccess(mediaFiles) //video captured successfully
{
var i=0;
alert(mediaFiles[i].fullPath);
alert(mediaFiles[i].size);
fileReader = new FileReader();
fileReader.onerror = function () {
alert("failed");
}
fileReader.onload = function (evt) {
alert(evt.target.result);
}
fileReader.readAsDataURL(mediaFiles[i].fullPath);
}
看来您不应该使用 FileReader,因为这不是它的用途。您最好尝试 VideoPlayer PhoneGap 插件。
https://github.com/phonegap/phonegap-plugins/tree/master /Android/VideoPlayer
It seems like you shouldn't be using FileReader because that's not what it's for. You're better off trying the VideoPlayer PhoneGap plugin.
https://github.com/phonegap/phonegap-plugins/tree/master/Android/VideoPlayer