How to get Path for local mp3 file from www in Phonegap IOS?

不问归期 提交于 2019-12-05 22:49:29

问题


i am using phonegap audio plugin in my phonegap app. I have some audio files stored in www/audio folder.

For android i used "file:///android_asset/www/audio" to read local file.

For IOS i need help.

Thanks


回答1:


Finally got it, reference:link

To get path i used this function

function getPhoneGapPath() {
   var path = window.location.pathname;
   path = path.substr( path, path.length - 10 );
   return path;
};

USAGE:

For IOS:

var snd = new Media( getPhoneGapPath() + 'test.mp3' );

For Android:prepend 'file://'

var snd = new Media( 'file://' + getPhoneGapPath() + 'test.mp3' );




回答2:


You will have trouble if called from a file other than 'index.html' because the part to trim off might not be 10 chars.

Try this:

// Get absolute file path on the device.
function getPhoneGapPath() {
    var path = window.location.pathname;
    var sizefilename = path.length - (path.lastIndexOf("/")+1);
    path = path.substr( path, path.length - sizefilename );
    return path;
};


来源:https://stackoverflow.com/questions/28339389/how-to-get-path-for-local-mp3-file-from-www-in-phonegap-ios

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