简体   繁体   English

读取大于20MB的文件时,Crosswalk使用cordova-plugin-file崩溃

[英]Crosswalk crashes with cordova-plugin-file when read file larger than 20MB

I'm using cordova-plugin-file to read my mp3 file with the readAsArrayBuffer method. 我正在使用cordova-plugin-file通过readAsArrayBuffer方法读取我的mp3文件。 It works perfect with a file less than 20mb, but with a larger file it causes the app to crash with this error. 它适用于小于20mb的文件,但是如果文件较大,则会导致应用程序因该错误而崩溃。 (I'm using crosswalk browser) (我正在使用人行横道浏览器)

E/chromium( 3330): [ERROR:simple_index_file.cc(223)] Failed to write the temporary index file E/chromium( 3330): [ERROR:runtime_javascript_dialog_manager.cc(69)] Not implemented reached in virtual void xwalk::RuntimeJavaScriptDialogManager::ResetDialogState(content::WebContents*)

I'm so confused with what the problem is. 我对这个问题很困惑。 Does the problem come from xwalk or cordova-plugin-file? 问题是否来自xwalk或cordova-plugin-file? Please help me because this plugin can only read file smaller than 20mb size. 请帮助我,因为此插件只能读取小于20mb的文件。

I found a solution for this bug. 我找到了解决此错误的方法。 I think Cordova-plugin-file can't send large amount of data from native to javascript. 我认为Cordova插件文件无法将大量数据从本机发送到javascript。 So I try to research from Crosswalk Browser API and very happy to see that they support File API . 因此,我尝试从Crosswalk Browser API中进行研究,非常高兴地看到它们支持File API It can get access directly to Android file system through virtual root like : EXTERNAL , CACHEDIR , DOWNLOADS , ... Here is the trick to read any big file with Crosswalk: 它可以通过virtual root直接访问Android文件系统,例如: EXTERNALCACHEDIRDOWNLOADS ,...这是使用Crosswalk读取任何大文件的技巧:

function readFileAsArrayBuffer(storage, path, file) {
    xwalk.experimental.native_file_system.requestNativeFileSystem(storage,
    function (fs) {
       fs.root.getFile(storage + "/" + path + file, {create: false}, function (entry) {
           entry.file(function (file) {
                reader = new FileReader();
                reader.onloadend = function (data) {
                   //Data after read.
                };
                  reader.readAsArrayBuffer(file);
                },
            },
            function (e) {
              console.error("2-" + JSON.stringify(e))
            });
        },
        function (e) {
          console.error("3-" + JSON.stringify(e));
        });
}
//test
readFileAsArrayBuffer("EXTERNAL", "downloads/folder/", "file.mp3");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM