The object of cellular communication iOS. How to access the resource in the www folder?

I am developing a telephone service application and I have an audio file that I want to play in a path like this www / Sounds / sound.mp3, and I'm trying to access this file using the Media Phonegap object to play it.

I can not understand the access path to this sound file in the javascript file that uses the Media object? I tried paths, for example, file: ///www/Sounds/sound.mp3, relative paths, etc., and I cannot access it. I keep getting the following error in xcode 4

Will attempt to use file resource 'file:///www/Sounds/sound.mp3'
Unknown resource 'file:///www/Sounds/sound.mp3'

Which path should I use to access the file? Or do I need to copy a sound file from my WWW directory and to the My Resources folder and access it?

In my WWW folder it is indicated, not sure if it matters.

+5
source share
6 answers

As with Cordova 3.3+, 2 other answers are incorrect. It should work even if you just give it the file name.

But it will only work in iOS if the file extension.wav .

This will work:

var media = new Media('recording.wav', ...);

It will not be:

var media = new Media('recording.mp3', ...);
+1
source

Here's a modified version of getPhoneGapPath that works for me on both iOS and Android. This is also not limited to working with files with a file name of 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 /

+12

window.location.pathname, . iPhone:

////{GUID}/{_}.app/WWW/index.html

Android:

/android_asset/www/index.html

/index.html, file:// Sounds/sound.mp3.

:

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

:

function getPhoneGapPath() {

    var path = window.location.pathname;
    path = path.substr( 0, path.length - 10 );
    return 'file://' + path;

};

var resource = getPhoneGapPath() + 'Sounds/sound.mps';
+8

. wav, mp3 caf iOS " ":

var media = new Media('beep.wav', ...);

, , www/ - www/beep.wav. www/sounds/, , www/. , :

var media = new Media('sounds/beep.wav', ...);

www/sounds/beep.wav.

+5

, API HTML5, ( "/" ):

function get_phonegap_path () {
 var path = window.location.pathname
 return path.slice(0, path.indexOf("/www/") + 5)
}
0

, Phone Gap Developer. , , - .

Media

$phonegap run android

$phonegap ios

js:

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();
Hide result

:

' var/mobile/Containers/data/Application/{GUID}/Library/NoCloud/ phonegapdevapp/www/assets/sounds/sound.mp3'

, .

: https://forums.adobe.com/thread/2135718

0

All Articles