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

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

我正在使用 cordova-plugin-file 通过 readAsArrayBuffer 方法读取我的 mp3 文件。它适用于小于 20mb 的文件,但对于更大的文件,它会导致应用程序崩溃并出现此错误。 (我使用的是人行横道浏览器)

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*)

我对问题出在哪里感到很困惑。问题是否来自 xwalk 或 cordova-plugin-file? 请帮助我,因为这个插件只能读取小于 20mb 大小的文件。

我找到了这个错误的解决方案。 我认为Cordova-plugin-file can't send large amount of data from native to javascript. So I try to research from Crosswalk Browser API and very happy to see that they support File API。它可以通过 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");