Play music? - Objective C
5 answers
Here is some sample code showing how to play a sound file on Mac OS X (10.5+). It uses the AudioQueue API.
Take a look at the code for aqplay.
+2
source to share
Since you tagged the question xcode
, take a look at NSSound and Apple Audio Review .
+1
source to share
-(void) playAlarmSound
{
// Get the filename of the sound file
NSString *path = [NSString stringWithFormat:@"%@%@",
[[NSBundle mainBundle] resourcePath],
@"/alarm.wav"];
// Declare a sound id
SystemSoundID soundID;
// get a URL for the sound file
NSURL *filepath = [NSURL fileURLWithPath:path isDirectory:NO];
// Use audio services to create sound
AudioServicesCreateSystemSoundID((CFURLRef) filepath, &soundID);
// Use audio services to play the sound
AudioServicesPlaySystemSound(soundID);
}
+1
source to share