2015-10-23 29 views
1

我正在使用cordova-plugin-file使用readAsArrayBuffer方法讀取mp3文件。它適用於小於20mb的文件,但是如果文件較大,則會導致應用程序崩潰並出現此錯誤。 (我使用人行橫道瀏覽器)當讀取大於20MB的文件時,Crosswalk與cordova-plugin-file崩潰

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大小的文件。

回答

1

我找到了這個錯誤的解決方案。 我認爲Cordova-plugin-file不能從本地發送大量的數據到javascript。所以我嘗試從Crosswalk Browser API進行研究,很高興看到它們支持File API。它可以通過virtual root直接獲取到Android文件系統的訪問,如:EXTERNALCACHEDIRDOWNLOADS,... 這裏是閱讀與人行橫道任何大文件的伎倆:

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"); 
相關問題