WebRTC에서 블루투스 헤드셋을 사용하고 싶습니다.

11820 단어 WebRTC

소개



Google이하는 WebRTC
htps : // ぇ brtc. 오 rg

이것의 Android native client를 사용해 보았지만, Bluetooth의 headset를 pairng해도 음성과 마이크가 본체에 연결되어, BT 디바이스에 routing되지 않기 때문에, 조금 만져 보았다.

결론부터 말하자면 AppRTCAudioManager.java
※ BT접속은 적당합니다.
public enum AudioDevice {
    SPEAKER_PHONE,
    WIRED_HEADSET,
    EARPIECE,
+    BLUETOOTH_HEADSET
  }

  public void init() {
    Log.d(TAG, "init");
    if (initialized) {
      return;
    }
___snip___
-    updateAudioDeviceState(hasWiredHeadset());
+    boolean btConnected = isBtHeadsetConnected();
+    updateAudioDeviceState(hasWiredHeadset(), btConnected);
+
+    // ここかなりサボってます。
+    // 本当はBT接続処理をちゃんとしないとだめですよ
+    if (btConnected) {
+      audioManager.startBluetoothSco();
+      audioManager.setBluetoothScoOn(true);
+    } else {

      // Register receiver for broadcast intents related to adding/removing a
      // wired headset (Intent.ACTION_HEADSET_PLUG).
      registerForWiredHeadsetIntentBroadcast();
+    }
___snip___



  /** Changes selection of the currently active audio device. */
  public void setAudioDevice(AudioDevice device) {
    Log.d(TAG, "setAudioDevice(device=" + device + ")");
    AppRTCUtils.assertIsTrue(audioDevices.contains(device));

    switch (device) {
      case SPEAKER_PHONE:
        setSpeakerphoneOn(true);
        selectedAudioDevice = AudioDevice.SPEAKER_PHONE;
        break;
      case EARPIECE:
        setSpeakerphoneOn(false);
        selectedAudioDevice = AudioDevice.EARPIECE;
        break;
      case WIRED_HEADSET:
        setSpeakerphoneOn(false);
        selectedAudioDevice = AudioDevice.WIRED_HEADSET;
        break;
+      case BLUETOOTH_HEADSET:
+        setSpeakerphoneOn(false);
+        selectedAudioDevice = AudioDevice.BLUETOOTH_HEADSET;
+        break;
      default:
        Log.e(TAG, "Invalid audio device selection");
        break;
    }
    onAudioManagerChangedState();
  }

+  private boolean isBtHeadsetConnected() {
+
+    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+    Set<BluetoothDevice> devices = adapter.getBondedDevices();
+
+    return (adapter.getProfileConnectionState(BluetoothProfile.HEADSET) ==
+            BluetoothProfile.STATE_CONNECTED);
+  }

  /** Unregister receiver for broadcasted ACTION_HEADSET_PLUG intent. */
  private void unregisterForWiredHeadsetIntentBroadcast() {
-    apprtcContext.unregisterReceiver(wiredHeadsetReceiver);
-    wiredHeadsetReceiver = null;
+    if (wiredHeadsetReceiver != null) {
+      apprtcContext.unregisterReceiver(wiredHeadsetReceiver);
+      wiredHeadsetReceiver = null;
+    }
  }

  /** Update list of possible audio devices and make new device selection. */
+  private void updateAudioDeviceState(boolean hasWiredHeadset, boolean hasBtHeadset) {
+    // Update the list of available audio devices.
+    audioDevices.clear();
+    if (hasBtHeadset) {
+      audioDevices.add(AudioDevice.BLUETOOTH_HEADSET);
+      setAudioDevice(AudioDevice.BLUETOOTH_HEADSET);
+    } else {
+      updateAudioDeviceState(hasWiredHeadset);
+    }
+  }

덧붙여서 Wired headset는 오리지날의 코드로 제대로 움직이고 있었습니다.

그 중 제대로 공부하자.
참고 참고로 했습니다. ぃ tp // m / t / ms / c60088 9829 9881d981

좋은 웹페이지 즐겨찾기