代码如下:
-(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实际上,根本不会播放任何声音,也不会调用完成回调。你知道这里会出什么问题吗?我想在播放当前声音之前停止任何以前的声音。
发布于 2010-06-06 09:01:46
AFAIK,仅支持.caf、.aif或.wav文件:
要播放您自己的声音,请将声音文件添加到应用程序包中;声音文件必须符合以下要求:
发布于 2009-07-19 01:14:59
err包含什么?由此,您应该能够推断出问题所在。
发布于 2012-07-04 21:17:07
您可以使用AudioToolBox框架来实现以下功能:
CFBundleRef mainbundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef = CFBundleCopyResourceURL(mainbundle, CFSTR("tap"), CFSTR("aif"), NULL);
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundFileObject);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
AudioServicesPlaySystemSound(1100);https://stackoverflow.com/questions/1149029
复制相似问题