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

后端 未结 6 1794
孤独总比滥情好
孤独总比滥情好 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:31

    Heres a modified version of getPhoneGapPath that works for me on both iOS and Android. It is also not restricted to only working on files that have a filename that is 10 characters long :)

    getPhoneGapPath: function () {
        'use strict';
        var path = window.location.pathname;
        var phoneGapPath = path.substring(0, path.lastIndexOf('/') + 1);
        return phoneGapPath;
    }
    
    var resource = getPhoneGapPath() + 'audio/audio.mp3';
    

    getPhoneGapPath() will return:

    iOS: /var/mobile/Applications/{GUID}/{appName}/www/

    Android: /android_asset/www/

提交回复
热议问题