延迟一段时间后播放音频文件
我有一个音频文件,我想在用户看到一些动画播放等后,以 20 秒的延迟开始播放......
有谁知道我会如何做到这一点?我有 5 个动画正在播放,之后我想要开始播放音频文件。整个过程将继续循环,直到用户退出应用程序。
这是我播放音频文件的代码。如果按下按钮或在 viewDidLoad 上,我可以让它播放,效果很好。
NSString *audioSoundPath = [[ NSBundle mainBundle] pathForResource:@"audio_file" ofType:@"caf"];
CFURLRef audioURL = (CFURLRef) [NSURL fileURLWithPath:audioSoundPath];
AudioServicesCreateSystemSoundID(audioURL, &audioID);
AudioServicesPlaySystemSound(audioID);
感谢您的帮助
I have an audio file that I want to begin playing at a 20 second delay, after the user has seen some animations play etc...
Does anyone know how I might go about doing this? I have 5 animations that play, after which I would like audio file to begin. The whole thing would keep cycling until the user exits the app.
Here's the code I have that plays the audio file. I can get it to play if a button is pressed or on viewDidLoad, that works fine.
NSString *audioSoundPath = [[ NSBundle mainBundle] pathForResource:@"audio_file" ofType:@"caf"];
CFURLRef audioURL = (CFURLRef) [NSURL fileURLWithPath:audioSoundPath];
AudioServicesCreateSystemSoundID(audioURL, &audioID);
AudioServicesPlaySystemSound(audioID);
thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您知道它总是正好 20 秒,那么您可以使用 NSTimer 调用启动音频的方法:
If you know its always going to be exactly 20 seconds then you can use an NSTimer to call a method that starts the audio:
您还可以使用
[self PerformSelector: @selector(playSound:) withObject: audioURL afterDelay: 20.0f];
You can also use
[self performSelector: @selector(playSound:) withObject: audioURL afterDelay: 20.0f];