【问题标题】:iOS - When starting a recording, the bluetooth device thinks I'm making a phone calliOS - 开始录音时,蓝牙设备认为我正在打电话
【发布时间】:2014-06-30 17:14:27
【问题描述】:

我有一个录音应用。我遇到了一个问题,当我打开我的应用程序并且手机与蓝牙设备配对时,一旦我开始录制,蓝牙设备就会认为我正在拨打电话。它会发出呼出的声音,并在屏幕上显示“ON CALL”(总是在谈论 BT 设备),但当然没有实际通话。

这就是我当前初始化会话的方式:

[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideNone
                                                   error:nil];

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
                                 withOptions:AVAudioSessionCategoryOptionMixWithOthers | 
                                             AVAudioSessionCategoryOptionAllowBluetooth
                                       error: nil];

我在 2 种不同的蓝牙设备上进行了尝试,类似的结果发生在相同的设备上。两者都尝试建立电话联系。

查看蓝牙日志后,我发现了一些关于它在做什么的线索:

12:24:07.185 A2DPClient.cpp:390        StopStreaming        A2DP       Notice     Stopping A2DP audio streaming
12:24:07.186 A2DPClient.cpp:415        StopStreaming        A2DP       Notice     Sending 'A2DP audio disconnected' event for device 00:19:B5:FE:05:9B "VW_RADIO_55"
12:24:07.201 HandsfreeAudioPlugIn.cpp:971 audioDataAvailable   Handsfree  Notice     HandsfreeAudioPlugIn:: Audio available event for 00:19:B5:FE:05:9B, reason: 2
12:24:07.203 HandsfreeAudioPlugIn.cpp:971 audioDataAvailable   Handsfree  Notice     HandsfreeAudioPlugIn:: Audio available event for 00:19:B5:FE:05:9B, reason: 4
12:24:07.203 HandsfreeAudioPlugIn.cpp:971 audioDataAvailable   Handsfree  Notice     HandsfreeAudioPlugIn:: Audio available event for 00:19:B5:FE:05:9B, reason: 1
12:24:07.203 HandsfreeGateway.cpp:699  createVisualVoicemai Handsfree  Notice     Setting up virtual call
12:24:07.205 AudioSendThread.cpp:91    run                  Audio      Notice     AudioSendThread stopping
12:24:07.207 HandsfreeGateway.cpp:1540 initiateScoConnectio Handsfree  Notice     Initiating SCO connection with delay of 20 milliseconds
12:24:07.207 HandsfreeGateway.cpp:3179 handleUpdateCallStat Handsfree  Notice     Updating call status for call(s): [ [#1: Outgoing to +XXXXXXXXXXXXX "My Number" (voicemail)] ]
12:24:07.207 HandsfreeGateway.cpp:1523 delayScoConnection   Handsfree  Notice     Delaying SCO connection by 20 milliseconds
12:24:07.208 HandsfreeGateway.cpp:3183 handleUpdateCallStat Handsfree  Notice     callPresent: no, callState: 1, callSetup: outgoing, heldStatus: none, heldChanged: no, visualVoicemail: yes
12:24:07.208 HandsfreeGateway.cpp:2871 tellEveryOneAboutVVM Handsfree  Notice     Sending call setup "outgoing" to device 00:19:B5:FE:05:9B "VW_RADIO_55"
12:24:07.208 HandsfreeGateway.cpp:2877 tellEveryOneAboutVVM Handsfree  Notice     Sending call status "call active" to device 00:19:B5:FE:05:9B "VW_RADIO_55"
12:24:07.208 HandsfreeGateway.cpp:2760 operator()           Handsfree  Notice     Sending call setup "none" to device 00:19:B5:FE:05:9B "VW_RADIO_55"
12:24:07.229 HandsfreeGateway.cpp:1626 internalConnectAudio Handsfree  Notice     Making outgoing audio connection to device 00:19:B5:FE:05:9B "VW_RADIO_55"
12:24:07.457 HandsfreeGateway.cpp:1161 audioEvent           Handsfree  Notice     Received audio connected event for device 00:19:B5:FE:05:9B "VW_RADIO_55"
12:24:07.471 A2DPClient.cpp:1384       SuspendCfm           A2DP       Notice     Successfully suspended stream to device 00:19:B5:FE:05:9B "VW_RADIO_55"
12:25:36.959 LeObserver.cpp:904        scanTimer            Discovery  Notice     Session "wirelessproxd-central-35-1" is now at scan level 3
12:25:59.599 HandsfreeAudioPlugIn.cpp:1050 audioPauseNotificati Handsfree  Notice     HandsfreeGateway::audioPauseNotification
12:25:59.599 HandsfreeGateway.cpp:726  deleteVisualVoicemai Handsfree  Notice     Cleaning up virtual call
12:25:59.599 HandsfreeGateway.cpp:1567 internalDisconnectAu Handsfree  Notice     Disconnecting audio from device 00:19:B5:FE:05:9B "VW_RADIO_55"

什么是设置虚拟通话???那时我在代码中唯一做的就是

[self.audioRecorder record];

self.audioRecorder 当然是AVAudioRecorder 的一个实例。

我怎样才能防止这种情况发生?

【问题讨论】:

    标签: ios bluetooth avaudiorecorder avaudiosession


    【解决方案1】:

    只要您想开始录制并且不允许蓝牙,请更改您的 AVAudioSession 选项:

    [[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideNone
                                                       error:nil];
    
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
                                     withOptions:AVAudioSessionCategoryOptionMixWithOthers
                                           error: nil];
    
    [self.audioRecorder record];
    

    录制完成后,在AVAudioRecorder 实例的委托调用上:

    - (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag

    重新设置您的AVAudioSession 选项以允许蓝牙AVAudioSessionCategoryOptionAllowBluetooth 这样AVAudioSession 将不会假定录音输入应作为来自连接的BT 设备的语音呼叫处理。

    【讨论】:

    • 但是如果有蓝牙设备,这不会断开我当前的播放与蓝牙设备的连接吗?
    • 是的......这并不理想,但您也可以存储当前播放的位置并在 setCategory 之后恢复它。 developer.apple.com/library/ios/documentation/Audio/Conceptual/…
    • 是的,这对我不起作用。这是一个卡拉 OK 应用程序,所以我需要播放才能继续 WHILE 录制。无论如何感谢您的建议。
    猜你喜欢
    • 2022-08-10
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 2017-01-10
    • 1970-01-01
    • 2014-01-20
    • 2013-10-25
    相关资源
    最近更新 更多