A month ago I started working with phonegap, html5, css3 and jQtouch.
I am working on an application and I need to play sound in the application. I have a serious problem with this task.
First I’ve found out that I can play .mp3 files through phonegap using the new Media(…) function. I am not sure about .wav files, can I play those?
Second I’ve found that files must be less than 30 sec, is this so?
Third I can’t find the right place for my sound files. My project structure is the following:
project
-- src
-- gen
-- assets
-- -- www
-- -- DANCE.mp3
-- -- jqtouch
-- -- -- (some folders and files)
-- -- phonegap.js
-- libs
-- res
I’ve tried placing the file in ‘www’ folder and creating a new one called ‘audio’. None of this gave me what I wanted.
I am using this code for executing the song:
function playStream() {
mp3file = new Media("DANCE.mp3",
function() {
alert("playAudio():Audio Success");
},
function(err) {
alert(err);
}
);
mp3file.play();
}
I use Android 2.1 Simulator and I’ve tried 2.2 as well without success.
I hope I was clear enough.
I am looking forward to hearing from you.
Yours,
Mihail Velikov
PhoneGap for Android lets you store local audio files in two places:
android_asset: file name must start with /android_asset/sound.mp3
sdcard: file name is just sound.mp3
If you place your DANCE.mp3 file in your project’s assets directory, then you can play it using the path:
(You can read the source for AudioPlayer.java in the Android PhoneGap sources to see how this works.)