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

前端 未结 2 1401
陌清茗
陌清茗 2021-01-14 02:08

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

相关标签:
2条回答
  • 2021-01-14 02:51

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

    0 讨论(0)
  • 2021-01-14 03:00

    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;
    };
    
    0 讨论(0)
提交回复
热议问题