2012년 2월 5일 일요일

iOS Play Sound Effects

1. AudioServicesPlaySystemSound : Cannot control sound volume
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:path ofType:@"wav"]];

if( soundID[index] == -1 )
AudioServicesCreateSystemSoundID((CFURLRef)url, &soundID[index]);

AudioServicesPlaySystemSound(soundID[index]);
2. AVAudioPlayer : Cannot use iPod/iPhone native music player
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:path ofType:@"wav"]];

NSError *error;

AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[player play];
3. CocosDenshion : With configure mode param, can use iPod/iPhone native music player and control sound volume
// initialize
[CDAudioManager configure:kAMM_FxOnly];

NSString *effect = [[NSBundle mainBundle] pathForResource:path ofType:@"wav"];

if( soundID[index] == -1 )
{
[[SimpleAudioEngine sharedEngine] preloadEffect:effect];
soundID[index] = 1;
}

[[SimpleAudioEngine sharedEngine] playEffect:effect];

댓글 없음:

댓글 쓰기