应用麦克风访问

时间:2019-08-06 11:56:58

标签: ios swift microphone

有时启动应用程序时,它会请求麦克风访问权限,但我并没有在应用程序中的任何位置请求它。我仅使用AVPlayer和AVNodeplayer播放mp3内容。知道为什么我被要求进行麦克风访问吗?

  var playerNode = AVAudioPlayerNode()
  var audioEngine = AVAudioEngine()
  var audioEngine = AVAudioEngine()
  let timeShift = AVAudioUnitTimePitch()

 func setup() {
    audioEngine.inputNode.reset()
    if playerNode.engine == nil {
        audioEngine.attach(playerNode)
        audioEngine.attach(timeShift)
    }
    audioEngine.connect(playerNode, to: timeShift, format: nil)
    audioEngine.connect(timeShift, to: audioEngine.mainMixerNode, format: nil)
    audioEngine.prepare()
    do {
        try audioEngine.start()
    } catch {
        print("Could not start audio engine")
    }
}

 func seekToPostionSong(value: Float, audioFile: AVAudioFile, duration: Float) {
    if audioEngine.isRunning != false{
        do {
            try audioEngine.start()
        } catch let nsErr {
            print(nsErr)
        }
    }

    if let nodetime = playerNode.lastRenderTime{
        let playerTime: AVAudioTime = playerNode.playerTime(forNodeTime: nodetime) ?? playerNode.lastRenderTime!
        let sampleRate = playerNode.outputFormat(forBus: 0).sampleRate
        let newsampletime = AVAudioFramePosition(Int(sampleRate * Double(value)))
        let length = duration - value
        let framestoplay = AVAudioFrameCount(Float(playerTime.sampleRate) * length)
        if framestoplay > 1000 {
            playerNode.scheduleSegment(audioFile, startingFrame: newsampletime, frameCount: framestoplay, at: nil,completionHandler: nil)
        }
    }
    LocalPlayer_manager.shared.isPaused = true
    playerNode.play()
}

有人可以向我解释如何停止麦克风访问吗?

1 个答案:

答案 0 :(得分:0)

删除此行

  

AudioEngine.inputNode.reset()

再试一次,这对您有帮助