Phonegap app playing mp3 using Media plugin does not work

非 Y 不嫁゛ 提交于 2019-12-06 16:28:49

I found the issue by myself. Android does not let read files on local storage or on sdcard via path starting from root /storage/sdcard0 /storage/sdcard1. So when we would like to access local storage or sdcard we must access it via file:///mnt/sdcard/ for sdcard and file:///mnt/storage/sdcard1/ for phone storage.

Small example how to read entries from sdcard or phone storage:

var path = 'file:///mnt/storage/sdcard1/'; 
window.resolveLocalFileSystemURL(path, function(entry){
    var reader = entry.createReader();
    reader.readEntries(showEntries);
});

function showEntries(entries){
   var entries = [];
   for(var i =0; i < entries.length; i++){
       var entry = entries[i];
       var data = {
           name: entry.name,
           path: entry.fullPath,
       };

       entries[i] = data;
   }

   console.log(JSON.stringify(entries));
}

Hope that this will help with same issue as I had because this is not documented in phonegap.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!