Play local file from www folder

I am trying to use Media PhoneGap 2.7.0 features to play a file that is locally stored in the www folder. No matter what I do or how I refer to the file, I cannot get it to work.

(The app is for iOs)

Error: "Cannot use audio file from resource xxxx", error code 1

I tried to set the path as follows:

"media/rock.mp3" "www/media/rock.mp3" "file://var/mobile/Applications/..../www/media/rock.mp3" "/var/mobile/Applications/..../www/media/rock.mp3" 

They all make the same mistake. However, playing the file remotely using an http address works fine.

Here is my code:

 function spillLyd_lokal() { var sti = window.location.pathname; sti = "file:/" + sti.replace('index.html', ''); var url = sti + "media/rock.mp3"; var my_media = new Media(url, function () { alert("playAudio():Audio Success"); }, function (err) { alert("playAudio():Audio Error: " + JSON.stringify(err)); } ); my_media.play(); 

}

+4
source share

Source: https://habr.com/ru/post/1495832/


All Articles