2009-08-18 59 views

回答

2

這裏是some sample code將告訴您如何在Mac OS X(10.5+)播放聲音文件。 它使用AudioQueue API。
看看aqplay代碼。

0

假設您希望播放預先錄製的音樂,請嘗試使用QTMovieView。有關於如何使用它的教程here

1
-(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); 
}