我的应用程序只想访问Airpod的麦克风(而不是扬声器),但是当我尝试从我的应用程序开始录制时,如果正在播放,它会转动音乐。我怎么只能使用 Airpod 的麦克风。我不想停止其他应用程序正在播放的任何音乐。
我尝试执行以下操作。此代码片段实际上可以从Airpod的麦克风获取输入,但会停止正在播放的任何其他歌曲。
try recordingSession.setCategory(.playAndRecord, mode: .measurement, options: .allowBluetooth)
try recordingSession.setActive(true)
audioRecorder = try AVAudioRecorder(url: audioFilename, settings: settings)
audioRecorder.delegate = self
audioRecorder.isMeteringEnabled = true
audioRecorder.prepareToRecord()
audioRecorder.record()
我不想停止其他应用程序正在播放的任何音乐。我只想使用Airpod的麦克风
试试这个
try recordingSession.setCategory(.playAndRecord, mode: .measurement, options: [.allowBluetoothA2DP, .mixWithOthers])
并在您AppDelegate
添加截取的此代码didFinishLaunchingWithOptions
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
try! AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.ambient, mode: AVAudioSession.Mode.default, options: AVAudioSession.CategoryOptions.mixWithOthers)
return true
}