ios - 异步声音

标签 ios objective-c cocoa-touch ios4 ios6

我有以下代码:

SystemSoundID soundID;
NSString *soundFile = [[NSBundle mainBundle] pathForResource: _sound ofType:@ "wav"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef) [NSURL fileURLWithPath:soundFile], &soundID);
AudioServicesPlaySystemSound(soundID);


    [UIView animateWithDuration: 0.6f
                          delay: 0.1f
                        options: UIViewAnimationTransitionCurlUp
                     animations:^{
                         [appDelegate.presstobook setFrame:  CGRectMake(136, appDelegate.window.frame.size.height - 50, 47, 47)];
                     }
                     completion:^(BOOL finished){

                         presstobook = NO;
                     }
     ];

我该怎么做才能在不影响其余代码的情况下播放声音?我根本不想播放声音来暂停代码?我如何更改代码以便异步播放声音而不影响其余代码?谢谢!

最佳答案

是什么让您认为这会暂停代码?文档说:

Because sound might play for several seconds, this function is executed asynchronously.

如果这里确实有东西阻塞,我猜它是 AudioServicesCreateSystemSoundID()。但即使这不会阻塞,每次你想播放声音时都创建其中一个可能不是一个好主意,尤其是如果你从未处理过它们。您应该在某种设置中创建一次,然后随时使用 AudioServicesPlaySystemSound() 播放它。

关于ios - 异步声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14449344/

相关文章:

objective-c - 扩展 UITableView 的单元格

ios - TTLauncherView 移除删除按钮

iPhone SDK : Delegate method not getting called-Troubleshooting

iphone - 如何在 iPhone 的 box2d 中创建路径

ios - 在 iOS 中显示长文本选项的最佳方式?

ios - JSQMessagesViewController : my message doesn't Show up

objective-c - Apple Mach-O 链接器 (ld) 使用 Switch 语句时出错?

ios - SpriteKit - 对在多个 SKNode 上运行的多个 SKAction 进行排序

javascript - Cordova InAppBrowserexecuteScript() 未在 iOS 中触发回调

objective-c - 设置 NSView 的背景颜色