当调用AudioServicesPlaySystemSound时,它会很好地播放之前创建的SystemSound。但是当我之后直接调用 AudioServicesDisposeSystemSoundID 时,没有播放声音。似乎声音资源在播放之前就被处理掉了。
但是在 this Stackoverflow-Question人们说,有必要处理 System-Sound 以避免内存泄漏。
这两种方法的正确方法是怎样的?我应该在几秒钟后用计时器调用 Dispose-Method 吗?或者创建一个单例,在第一次调用 Play-Method 时创建一次声音资源,并在单例的 dealloc 中处理资源?
- (void) playSound {
NSURL *url = [[NSBundle mainBundle] URLForResource: @"SentMessage"
withExtension: @"wav"];
SystemSoundID mBeep;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &mBeep );
AudioServicesPlaySystemSound(mBeep);
AudioServicesDisposeSystemSoundID(mBeep);
}
最佳答案
您可以使用 AudioServicesAddSystemSoundCompletion
注册一个回调,以便在您的声音播放完毕时调用。您可以在那里处理系统声音。
或者在你类(class)的dealloc
中。
关于iOS 8 : AudioServicesPlaySystemSound is not playing Sound when AudioServicesDisposeSystemSoundID is called afterwards,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29614179/