View
 

Sounds

Page history last edited by Devon Weller 5 mos ago

I like Phonegap a lot! Just wondering, how can I insert an audioplayer with Phonegap in my iPhone app? Or any audio at all?

 

HowTo

  • Place your beep.wav in the Resources folder
  • Execute new Media('beep.wav').play();
    • See notification source in demo code

 

Supported Devices

  • iphone
    • Formats: .wav, .aiff
    • Note that while .mp3 works in the Simulator, it does not work on the actual device (On the EDGE version >= 0.8.2, .mp3 works on the device).

?

 

In the edge version of phonegap, the sound file must be included in the www folder.  For the above example, beep.wav would need to be in the www folder.  Older versions of PhoneGap may have required the file to be in the Resources group of your xcode project.

 

You may also reference audio files in a subfolder.  Executing new Media('audio/mysound.wav').play(); will play a wave file in www/audio/mysound.wav.

 

To loop a sound, pass the option "numberOfLoops" like this:

 

new Media('audio/mySong.wav').play({numberOfLoops:99});

 

 

References

 

Feature Requests / Plans

Comments (3)

profile picture

Joshua said

at 5:54 pm on Mar 5, 2009

I know that you can play short audio sounds, but I'm stumped about adding longer audio in here without it going through QuickTime. Is this possible?

profile picture

Brack said

at 1:41 pm on Mar 8, 2010

I'm also starting out with the Media class, and was wondering if it's possible to stream the audio via URL, or if Media only plays local files... or maybe I have to write device-specific code to buffer the url to a local file?

profile picture

raul silva said

at 9:27 am on May 19, 2010

Sounds are playing fine but I need to be able to listen for play done events so I can trigger an action when the sound is done playing. Does the Media object provide such a mechanism or is it limited to Stop and Play?

You don't have permission to comment on this page.