所以我为我工作的医院制作了一个音板,它播放不同的呼吸音供 RT 收听,也用于继续教育和受训人员。我可以停下来开始听起来很好。我遇到的问题是声音何时完成。你必须点击任何按钮两次才能播放下一个声音。所以我想知道你将如何在完成后重置声音文件。我是 obj-c 的新手,我的直觉告诉我要实现 NSTime,但我不知道该怎么做,或者这是否是我想要做的。
提前致谢!
- (IBAction)play {
if (soundIsPlaying == YES) {
[audioplayer release];
soundIsPlaying = NO;
}
else if (soundIsPlaying == NO) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"breathe1" ofType:@"wav"];
audioplayer=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
audioplayer.delegate = self;
audioplayer.volume = 1.2;
audioplayer.numberOfLoops = 0;
[audioplayer play];
soundIsPlaying = YES;
}
}
最佳答案
如果您使用的是 AVAudioPlayer,则可以设置一个名为 numberOfLoops 的属性。 查看 Apple 网站上的 AVAudioPlayer 类引用。
关于ios - Xcode iOS : How to reset a sound once it has played using AVFoundation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8584387/