2010-10-08 88 views
4

我有,我想开始在20秒延迟播放音频文件后,用户已经看到了一些动画播放等后...播放音频文件的时间延迟

有谁知道我怎么可能去做这个?我有5个动画,播放后,我想音频文件开始。整个事情将继续骑自行车,直到用户退出应用程序。

这是我播放音频文件的代码。如果按下按钮或viewDidLoad,我可以播放它,这可以正常工作。

NSString *audioSoundPath = [[ NSBundle mainBundle] pathForResource:@"audio_file" ofType:@"caf"]; 
CFURLRef audioURL = (CFURLRef) [NSURL fileURLWithPath:audioSoundPath]; 
AudioServicesCreateSystemSoundID(audioURL, &audioID); 

AudioServicesPlaySystemSound(audioID); 

感谢您的帮助

回答

3

如果你知道它始终将是整整20秒钟,然后你可以使用一个NSTimer调用启动音频的方法:

[NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@selector(startPlaying) userInfo:nil repeats:NO]; 


-(void)startPlaying { 

    NSString *audioSoundPath = [[ NSBundle mainBundle] pathForResource:@"audio_file" ofType:@"caf"]; 
    CFURLRef audioURL = (CFURLRef) [NSURL fileURLWithPath:audioSoundPath]; 
    AudioServicesCreateSystemSoundID(audioURL, &audioID); 
    AudioServicesPlaySystemSound(audioID); 
} 
+0

应该做的伎俩。非常感谢。 – hanumanDev 2010-10-08 14:56:22

2

你可以也使用

[self performSelector: @selector(playSound:) withObject: audioURL afterDelay: 20.0f];

+0

当然你可以选择传递任何你想要的参数,只要它可以被转换为'id'。 – jv42 2010-10-08 14:52:16

+0

很棒。非常感谢。 – hanumanDev 2010-10-08 14:56:49