Reputation: 2370
Hi i'm trying to build a web view mobile app using cordova and intel xdk the problem is i can play sound from the ide emulator but when building the project to apk and installed on my android phone then trying to play the sound it not work i google it a lot but nothing help..
my code :
var audio = new Audio('audio/7.wav');
audio.play();
i manage to get the actual path for the sound file when playing it on the emlitor and it is like this
i tried to get the path using the same function that returns the actual path for the sound file on android phone but the path was empty so i figured out when building the project to app it change the folder and the assets folder to this
so it changing every path in the app by adding new folder and i'm trying to play the sound from the apk locally not set the sound on server and play it from there please any help and many thanks in advance
Upvotes: 0
Views: 817
Reputation: 343
I know its too late for the answer but anyway i am posting this so that anyone might need help.
As the question said he is using Cordova.
Cordova will have plugin called Media which let you play audio in the app.
you can use it like:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var my_media = new Media('cdvfile://localhost/temporary/recording.mp3', ...);
}
media.play;
Remember:
Always use the Media inside the device ready function else it will not be played.
For more reference check its official page => Cordova Media Plugin.
Upvotes: 0
Reputation: 166
If you are using local files, try to reference them with src="file:///path/youfilename.mp3"
Upvotes: 0