tags:

views:

63

answers:

2

Hi , i have buttons on my application and have a short sound effect , when user taps on buttons , short sound plays but if someone listen to the music , the music will stop ! how can i handle this ? to play music and my effect ,i use AudioToolbox framework . i read apple documentation doesn't work with AVFoundation.framework ! for some reasons i can't change my code ! is there any way for systemSoundID ?

-(void)soundType{

NSString *path = [NSString stringWithFormat:@"%@%@",[[NSBundle mainBundle] resourcePath], @"/type.wav"];

SystemSoundID soundID;

NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];

AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);

AudioServicesPlaySystemSound(soundID);

}

+1  A: 

You can try using NSSound

NSSound *snd = [[NSSound alloc] initWithContentsOfFile: fileName byReference: NO];
[snd play];
cooltechnomax
what is NSSound ! because didnt find any thing in Foundation Framework
Momeks
NSSound is a simple interface for playing back sound files such as AIFF, WAV and .snd files. its not in foundation framework, its provided by Application Kit. You can explore NSSound. For Reference:http://developer.apple.com/mac/library/documentation/cocoa/reference/ApplicationKit/Classes/NSSound_Class/Reference/Reference.html
cooltechnomax
+1  A: 

Do you mean that when iPod music is playing and you run your app, the music stops? If so, you should set your audio session to ambient sound so that the iPod can continue playing. Try this:

AudioSessionInitialize(NULL, NULL, NULL, self);
UInt32 category = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);  
AudioSessionSetActive(YES);
Luke
works great :) thanks .
Momeks