When to go with AVAudioPlayer on iPhone SDK

March 28, 2009 § Leave a comment

How do we make decision on which Audio framework to use? Beside the obvious reasons such as AVAudioPlayer support OS 2.2 and above, AVAudioPlayer won’t have 30 sec limitation, there is another undocumented audio benefit. AVAudioPlayer play significant louder, almost twice as loud than the same audio file played by AudioServicesPlaySystemSound.

If you desire dynamic sounds varying from low to high, AVAudioPlayer is definitely the best choice in audio selection.

// Using AVAudioPlayer
AVAudioPlayer *player;
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@”sound” ofType:@”wav”];
player =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: soundPath] error:nil];
player.volume = 1.0;
player.numberOfLoops = 0;
[player prepareToPlay];
[player play];

// Using AudioServicesPlaySystemSound
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@”sound” ofType:@”wav”];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundPath], &soundID);
AudioServicesPlaySystemSound (soundID);
[soundPath release];

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading When to go with AVAudioPlayer on iPhone SDK at Web Builders.

meta

%d bloggers like this: