ios - Xcode iOS : How to reset a sound once it has played using AVFoundation

标签 ios xcode avfoundation audio

所以我为我工作的医院制作了一个音板,它播放不同的呼吸音供 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/

相关文章:

iOS TableView(错误 : two scroll Bars Found As Zoomed)

ios - Xcode 7.0.1 在 header 搜索路径中找不到文件

iOS + Xcode + Swift 4.2 从 iOS 设备向 APN 发送消息

ios - 如何获得可无延迟拖动的 MKAnnotationView?

ios - 无法测试文档提供程序扩展

ios - 无法从ios objective-c 中的UIDatePicker获取回历日期?

ios - AVPlayerPeriodicCaller 崩溃

macos - 如何从 AVPlayer 获得流畅的高速率播放?

ios - 使用 PHP 在 Objective-C 中上传录制的音频文件

ios - 对于 Soap NSURLConnection,请确保您的应用支持 IPv6 网络,因为需要 IPv6 兼容性