【问题标题】:Asynchronous sounds异步声音
【发布时间】:2013-01-05 03:21:02
【问题描述】:

我有以下代码:

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;
                     }
     ];

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

【问题讨论】:

    标签: ios objective-c cocoa-touch ios4 ios6


    【解决方案1】:

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

    因为声音可能会播放几秒钟,所以这个函数是异步执行的。

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

    【讨论】:

      猜你喜欢
      • 2013-03-12
      • 2017-12-07
      • 1970-01-01
      • 1970-01-01
      • 2010-11-12
      • 1970-01-01
      • 2011-08-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多