Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  141] [ 2]  / answers: 1 / hits: 16169  / 14 Years ago, thu, november 11, 2010, 12:00:00

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


More From » android

 Answers
6

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:



mp3file = new Media(/android_asset/DANCE.mp3,
function() {
alert(playAudio():Audio Success);
},
function(err) {
alert(err);
}
);
mp3file.play();


(You can read the source for AudioPlayer.java in the Android PhoneGap sources to see how this works.)


[#94997] Wednesday, November 10, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stacie

Total Points: 476
Total Questions: 92
Total Answers: 102

Location: Bosnia and Herzegovina
Member since Tue, Mar 29, 2022
2 Years ago
stacie questions
Fri, Jun 26, 20, 00:00, 4 Years ago
Thu, Jan 23, 20, 00:00, 4 Years ago
Fri, Aug 30, 19, 00:00, 5 Years ago
Fri, Aug 2, 19, 00:00, 5 Years ago
;