我怎样才能preLOAD声音? [英] How can I preload a sound?

查看:264
本文介绍了我怎样才能preLOAD声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPhone应用程序,我播放声音,当用户正在测试。除了作品的首次的声音播放时,有一个延迟,我认为加载声音到内存很大。我怎样才能preLOAD的声音?这里是我的code的声音:

I have an iPhone app where I play a sound when the user is taking a test. Works great except for the first time the sound plays when there is a delay, I assume loading the sound into memory. How can I preload the sound? Here is my code for the sound:

- (void)doBuzz:(id)sender {
SystemSoundID buzzsoundID;
NSString *buzzsoundFile = [[NSBundle mainBundle]
                           pathForResource:@"buzz" ofType:@"caf"];

AudioServicesCreateSystemSoundID((CFURLRef)
                                 [NSURL fileURLWithPath:buzzsoundFile]
                                 , &buzzsoundID);
AudioServicesPlaySystemSound(buzzsoundID);

}

推荐答案

我移动我的SystemSoundID申报到我的UIViewController的.h文件中固定我的声音延迟的问题,然后设置的NSString和viewDidLoad中被称为AudioServicesCreateSystemSoundID。然后,当我想打的声音,而不是调用doBuzz方法,我只是取代了与AudioServicesPlaySystemSound。

I fixed my sound delay problem by moving my declaration for the SystemSoundID into the .h file of my UIViewController and then set the NSString and called AudioServicesCreateSystemSoundID from ViewDidLoad. Then when I wanted to play the sound, rather than calling the doBuzz method I simply replaced that with AudioServicesPlaySystemSound.

这篇关于我怎样才能preLOAD声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆