How to get Path for local mp3 file from www in Pho

2020-03-01 20:01发布

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

2条回答
看我几分像从前
2楼-- · 2020-03-01 20:39

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;
};
查看更多
混吃等死
3楼-- · 2020-03-01 20:41

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' );

查看更多
登录 后发表回答