下面是代碼:使用系統聲音播放聲音
-(void)stop
{
NSLog(@"Disposing Sounds");
AudioServicesDisposeSystemSoundID (soundID);
//AudioServicesRemoveSystemSoundCompletion (soundID);
}
static void completionCallback (SystemSoundID mySSID, void* myself) {
NSLog(@"completion Callback");
}
- (void) playall: (id) sender {
[self stop];
AudioServicesAddSystemSoundCompletion (soundID,NULL,NULL,
completionCallback,
(void*) self);
OSStatus err = kAudioServicesNoError;
NSString *aiffPath = [[NSBundle mainBundle] pathForResource:@"slide1" ofType:@"m4a"];
NSURL *aiffURL = [NSURL fileURLWithPath:aiffPath];
err = AudioServicesCreateSystemSoundID((CFURLRef) aiffURL, &soundID);
AudioServicesPlaySystemSound (soundID);
NSLog(@"Done Playing");
}
輸出:
Disposing Sounds
Done Playing
在實際沒有聲音得到根本發揮和完成回叫不叫爲好。任何想法在這裏可能是錯的? 我想在播放當前之前停止任何以前的聲音。
我打印ERR使用NSLog和apears(null) – Shoaibi 2009-07-19 01:37:31