iOS Phonegap Media Object - How do I access a resource in the WWW folder?

后端 未结 6 1823
孤独总比滥情好
孤独总比滥情好 2020-12-29 00:00

I\'m developing an application with phonegap, and I have a sound file I want to play that\'s in a path like so www/Sounds/sound.mp3, and I\'m trying to access this file usin

6条回答
  •  暖寄归人
    2020-12-29 00:07

    Use window.location.pathname to get the path of your application. It will look something like this on iPhone:

    /var/mobile/Applications/{GUID}/{appname}.app/www/index.html

    And this on Android:

    /android_asset/www/index.html

    Strip off the /index.html, prepend file://, and append your relative path Sounds/sound.mp3.

    Here's something to get you started:

    Demo: http://jsfiddle.net/ThinkingStiff/chNVY/

    Code:

    function getPhoneGapPath() {
    
        var path = window.location.pathname;
        path = path.substr( 0, path.length - 10 );
        return 'file://' + path;
    
    };
    
    var resource = getPhoneGapPath() + 'Sounds/sound.mps';
    

提交回复
热议问题