首页 > 解决方案 > 请求访问麦克风的简单播放

问题描述

我的应用程序中有一个声音剪辑。现在,iOS 正在请求访问麦克风。这对于简单的播放有必要吗?这是代码片段:

func _playSound() {
    do {
        if let fileURL = Bundle.main.path(forResource: "clip", ofType: "aiff") {
            _clip = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: fileURL))
            _clip?.volume = 0.3
        } else {
            print("ERROR: No file with specified name exists in _playSound()")
        }
    } catch let error {
        print("ERROR: AVAudioPlayer(contentsOf: _) threw an error in _playSound(); Message: \(error.localizedDescription)")
    }
    _clip?.play()
}

标签: iosswiftavfoundationplayback

解决方案


推荐阅读