我已经实现了一个流式传输音频和视频的应用。该应用程序还具有chromecast支持。这是我的问题:如果我将音频流式传输到连接的蓝牙设备,那么我浏览到试图发现chromecast设备的活动,蓝牙连接进入坏状态(播放切换回我的设备,但蓝牙连接说明蓝牙设备仍然连接)。如果我注释掉执行chromecast设备发现的代码,蓝牙连接就可以了。这是代码行,当取消注释时,会导致连接终止:
mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback,
MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
以下是我在日志中看到的内容:
10-29 18:30:31.098 843-10255/? D/NetlinkSocketObserver﹕ NeighborEvent{elapsedMs=1128444524, 10.0.0.1, [CCA4620B2A21], RTM_NEWNEIGH, NUD_REACHABLE}
10-29 18:30:31.429 843-1680/? W/ActivityManager﹕ Permission Denial: Accessing service ComponentInfo{com.google.android.music/com.google.android.music.dial.DialMediaRouteProviderService} from pid=12704, uid=10386 that is not exported from uid 10060
10-29 18:30:31.436 1805-1805/? I/Keyboard.Facilitator﹕ onFinishInput()
10-29 18:30:31.450 198-14249/? I/bt_a2dp_hw﹕ out_set_parameters: state 1
10-29 18:30:31.450 198-14249/? I/str_params﹕ key: 'routing' value: '128'
10-29 18:30:31.450 198-14249/? I/str_params﹕ key: 'a2dp_sink_address' value: 'BC:85:56:38:15:B2'
10-29 18:30:31.459 12704-13205/com.testapp.android W/AudioTrack﹕ dead IAudioTrack, PCM, creating a new one from obtainBuffer()
10-29 18:30:31.470 198-835/? D/audio_hw_primary﹕ out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
10-29 18:30:31.480 198-834/? D/audio_hw_primary﹕ select_devices: out_snd_device(2: speaker) in_snd_device(0: none)
10-29 18:30:31.480 198-834/? D/msm8974_platform﹕ platform_send_audio_calibration: sending audio calibration for snd_device(2) acdb_id(15)
10-29 18:30:31.480 198-834/? D/audio_hw_primary﹕ enable_snd_device: snd_device(2: speaker)
10-29 18:30:31.483 198-834/? D/audio_hw_primary﹕ enable_audio_route: apply and update mixer path: low-latency-playback
10-29 18:30:31.535 843-1911/? W/AudioTrack﹕ dead IAudioTrack, PCM, creating a new one from processAudioBuffer()
10-29 18:30:31.565 198-835/? D/audio_hw_primary﹕ out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
10-29 18:30:31.961 14798-14798/? D/ChimeraCfgMgr﹕ Loading module com.google.android.gms.cast from APK com.google.android.gms
10-29 18:30:31.966 14798-14340/? D/MdnsClient﹕ Multicast lock held. Releasing
10-29 18:30:31.967 14798-14340/? D/MdnsClient﹕ #acquireLock. Multicast lock not held. Acquiring
10-29 18:30:33.424 12704-13190/com.testapp.android D/com.testapp.android.sqlite.LocalPlaybackPositionTableHelper﹕ - updated playback position to 23
10-29 18:30:34.530 198-14249/? I/bt_a2dp_hw﹕ suspend_audio_datapath: state 1
10-29 18:30:34.533 14175-14200/? E/bt_btif﹕ bta_av_str_stopped:audio_open_cnt=1, p_data ab20aea4
10-29 18:30:34.533 14175-14200/? W/bt_btif﹕ bta_dm_rm_cback:2, status:6
10-29 18:30:34.576 14175-14200/? W/bt_btif﹕ bta_dm_rm_cback:2, status:6
10-29 18:30:34.584 198-14249/? I/bt_a2dp_hw﹕ skt_disconnect: fd 25
10-29 18:30:34.584 14175-14214/? E/bt_btif﹕ warning : no command pending, ignore ack
10-29 18:30:34.584 14175-14214/? W/bt_btif﹕ pcm bytes per tick 3528
10-29 18:30:34.584 14175-14193/? I/BluetoothA2dpServiceJni﹕ bta2dp_audio_state_callback
10-29 18:30:34.585 14175-14213/? D/A2dpStateMachine﹕ Connected process message: 101
10-29 18:30:34.585 14175-14213/? D/A2dpStateMachine﹕ A2DP Playing state : device: BC:85:56:38:15:B2 State:10->11
我正在测试运行Android 6.0的Nexus 5。有任何想法吗?提前谢谢!
答案 0 :(得分:0)
更新:因此,经过一系列测试后,我发现如果没有选择媒体路线,我会错误地执行以下操作:
mMediaRouter.selectRoute(mMediaRouter.getDefaultRoute());
这导致蓝牙连接丢失。