【发布时间】:2012-01-19 17:50:11
【问题描述】:
我有一个音频文件,当用户单击一个视图时播放。我的问题是,如果他们移动到另一个视图,音频会继续播放。如果用户不再在该视图中,我希望音频停止。
这是在 viewDidUnload 方法中完成的吗?
这是延迟 15 秒后播放音频的代码:
-(void)startPlaying {
[NSTimer scheduledTimerWithTimeInterval:15 target:self selector:@selector(startPlaying) userInfo:nil repeats:NO];
NSString *audioSoundPath = [[ NSBundle mainBundle] pathForResource:@"audio_file" ofType:@"caf"];
CFURLRef audioURL = (CFURLRef) [NSURL fileURLWithPath:audioSoundPath];
AudioServicesCreateSystemSoundID(audioURL, &audioID);
AudioServicesPlaySystemSound(audioID);
}
感谢您的帮助。
【问题讨论】:
标签: iphone objective-c core-audio