插入耳机后,我只能听到录音机的音频

时间:2019-05-07 10:29:49

标签: ios swift avaudioplayer avaudiorecorder

因此,当我使用模拟器按预期工作时,我正在尝试对其进行录音和音频播放,但是在我的电话或任何电话上,我只能使用耳机听见吗?这是我的录音和播放功能 更新:我注意到手机上的重新编码不能正常工作:“端口扬声器”的选定数据源未知”

  func startRecording() {
        let audioFilename = getDocumentsDirectory().appendingPathComponent("recording.m4a")
        let settings = [
            AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
            AVSampleRateKey: 12000,
            AVNumberOfChannelsKey: 1,
            AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
        ]

        do {
            audioRecorder = try AVAudioRecorder(url: audioFilename, settings: settings)
            audioRecorder.delegate = self
            audioRecorder.record()
        } catch {
            print(error.localizedDescription)
        }
    }

    func getDocumentsDirectory() -> URL {
        let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
        return paths[0]
    }



  func playAudio(fileData:Data){
        do {
            audioPlayer = try AVAudioPlayer(data: fileData)
            if let audioPlayer = audioPlayer {
                audioPlayer.delegate  = self
                audioPlayer.prepareToPlay()
                audioPlayer.volume = 2.0
                audioPlayer.play()
            }
        } catch {
            print(error.localizedDescription)
        }
    }

0 个答案:

没有答案