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

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

    I had the same problem and all the answers about file paths alone didn't work for me using the Phone Gap Developer app. The problem was with the Developer app not pushing the files physically onto the device, preventing me from accessing them in any way.

    The Media plugin worked as intended using

    $ phonegap run android

    $ phonegap run ios

    with this js code:

    function getPhoneGapPath() {
      var path = window.location.pathname;
      var phoneGapPath = path.substring(0, path.lastIndexOf('/') + 1);
       return phoneGapPath;
    }
    var sound = new Media(getPhoneGapPath()+"assets/sounds/sound.mp3"
    //...
    sound.play();

    This returns an error on Developer app:

    'Cannot use audio file from source var/mobile/Containers/data/Application/{GUID}/Library/NoCloud/phonegapdevapp/www/assets/sounds/sound.mp3'

    but works if built from the console.

    Details can be found here: https://forums.adobe.com/thread/2135718

提交回复
热议问题