How do you play sounds on the iPhone?
Hi friends!
I would like to know your opinions.
I'm using C++ and OpenGL (minimun APPLE's API), what should I use to play sounds? Do you know any sample/library or source code?
I know there is a sample, but it is said it has bugs. FMOD cost 500 $ which a bit expensive for a small project.
Any suggestion?
Thanks a lot
I would like to know your opinions.
I'm using C++ and OpenGL (minimun APPLE's API), what should I use to play sounds? Do you know any sample/library or source code?
I know there is a sample, but it is said it has bugs. FMOD cost 500 $ which a bit expensive for a small project.
Any suggestion?
Thanks a lot
I'd recommend OpenAL. If I'm not mistaken, the iPhone comes with an implementation of it.
Depending on what you want to play, there are much easier solutions than OpenAL.
If you want to play a sound <30seconds in duration and in .caf, .aiff, .wav format, use AudioService.
If you want to play a more "complicated" audio format, such as mp3, or it is longer than 30 seconds in duration, use the new AVAudioPlayer.
If you want to play a sound <30seconds in duration and in .caf, .aiff, .wav format, use AudioService.
Code:
#import <AudioToolbox/AudioToolbox.h>
//creating it
SystemSoundID shortSound;
NSURL* audioFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"photoShutter"
ofType:@"aiff"]];
AudioServicesCreateSystemSoundID((CFURLRef)audioFile, &shortSound);
//playing it
AudioServicesPlaySystemSound(shortSound);
//cleanup
AudioServicesDisposeSystemSoundID(shortSound);If you want to play a more "complicated" audio format, such as mp3, or it is longer than 30 seconds in duration, use the new AVAudioPlayer.
Code:
#import <AVFoundation/AVFoundation.h>
//Creating it
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"Music"
ofType:@"mp3"]];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile
error:nil];
//Playing it
[audioPlayer play];
AVAudioPlayer, new to iPhone OS 2.2, is a fairly easy way to play audio. I recommend that.
KB Productions, Car Care for iPhone/iPod Touch
@karlbecker_com
All too often, art is simply the loss of practicality.
Thanks a lot for replies!
I would like to add sound to my game, I mean, sound FX and ambient music. I guess format should be MP3 (but I'm not sure)
So, is AVAudioPlayer part of the iPhone API? Is a bad idea play mp3 with this an at the same time real time 3d graphics? Can I use AVAudioPlayer on C++ or should I create a wrapper?
Thanks friends!
I would like to add sound to my game, I mean, sound FX and ambient music. I guess format should be MP3 (but I'm not sure)
So, is AVAudioPlayer part of the iPhone API? Is a bad idea play mp3 with this an at the same time real time 3d graphics? Can I use AVAudioPlayer on C++ or should I create a wrapper?
Thanks friends!
What about if I wanted to play sounds at different speeds, like a dj scratching a record?
longjumper Wrote:Depending on what you want to play, there are much easier solutions than OpenAL.
If you want to play a sound <30seconds in duration and in .caf, .aiff, .wav format, use AudioService.
Code:
#import <AudioToolbox/AudioToolbox.h>
//creating it
SystemSoundID shortSound;
NSURL* audioFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"photoShutter"
ofType:@"aiff"]];
AudioServicesCreateSystemSoundID((CFURLRef)audioFile, &shortSound);
//playing it
AudioServicesPlaySystemSound(shortSound);
//cleanup
AudioServicesDisposeSystemSoundID(shortSound);
If you want to play a more "complicated" audio format, such as mp3, or it is longer than 30 seconds in duration, use the new AVAudioPlayer.
Code:
#import <AVFoundation/AVFoundation.h>
//Creating it
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"Music"
ofType:@"mp3"]];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile
error:nil];
//Playing it
[audioPlayer play];
I am trying to play multiple files (sound1.wav, sound2.wav, sound3.wav, etc...)
after a button is pushed and have used your code in a loop and tried copying it three times, but it simply will not play one file after the other. Do I need to queue the sound files? I also noticed a method called: AudioServicesAddSystemSoundCompletion but am not sure how to implement it.
PLEASE help I have been struggling for days to get my program to play a few files one after the other.
Thank you so much.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Playing sounds and music on iPhone, which API to use? | Jamie W | 17 | 8,293 |
Apr 20, 2010 07:55 AM Last Post: Beast |
|
| how to play short sounds asynchronously | ishaq | 1 | 2,868 |
Sep 11, 2008 10:03 PM Last Post: AnotherJake |
|

