Open alexsafe opened 4 hours ago
Hello,
If you want use bluetooth microphone or other audio source you can try use setPreferedDevice method in MicrophoneSource:
val audioManager = context?.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
val devices = audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)
//check the list and select the device required
val deviceSelected = ....
(genericStream.audioSource as MicrophoneSource).setPreferredDevice(deviceSelected)
//set null value to reset to default value
(genericStream.audioSource as MicrophoneSource).setPreferredDevice(null)
Other possible solution is connect the device using bluetooth android API and the microphone should switch atumatically to that device: https://stackoverflow.com/questions/33757491/android-recording-audio-from-bluetooth-headset-sometimes-records-from-the-mic Maybe you need do it before start the audio source.
Thanks. This doesn't seem to work. I've tried in various ways, but basically this would be it: I left some comments there.
val audioManager = context?.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
val devices = audioManager?.getDevices(AudioManager.GET_DEVICES_INPUTS)
audioManager?.mode = AudioManager.MODE_NORMAL
audioManager?.setBluetoothScoOn(true);
devices?.mapNotNull { device ->
log.d("Type: ${device.getType()}")
log.d("Product Name: ${device.getProductName()}")
when (device.type) {
AudioDeviceInfo.TYPE_BUILTIN_MIC -> "Built-in Microphone"
AudioDeviceInfo.TYPE_BLUETOOTH_SCO -> {
log.d("micsource ${micSource.audioSource} ..,. ${micSource.preferredDevice?.type}")
val source = rtmpStream.audioSource as MicrophoneSource
// source.audioSource = MediaRecorder.AudioSource.CAMCORDER
source.setPreferredDevice(device)
// changeAudioSource(if (config.with_audio) phoneMicSource else NoAudioSource())
}
else -> null
}
}
If I move that block of code into the AudioDeviceInfo.TYPE_BUILTIN_MIC case it works just fine - for the built in mic
Hi,
I am looking for ways to select the audio source, if possible independent of the video source. I searched the previous issues maybe these 2 qualify #1139 #782 , sorry if it's discussed someplace else that I missed.
What I tried:
I have a custom
class FlexibleMicrophoneSource( var audioSource: Int = MediaRecorder.AudioSource.CAMCORDER ): AudioSource(), GetMicrophoneData { private val microphone = MicrophoneManager(this) microphone.setPreferredDevice(preferredDevice)
I am checking the available devices from AudioManager and I chose the Bluetooth one.AudioDeviceInfo.TYPE_BLUETOOTH_SCO -> { preferredDevice = device
I figured this might be the hardest to connect. But it could also be USB, or HDMI. So far I was able to use the phone mic when USB is connected, but when HDMI is connected it takes priority. (Yes, I have a device with USB and HDMI ports).
When I tried the code above to get the mic from the Bluetooth headphones (that I have paired with my phone and is used as default mic/sound) nothing happened and the sound source was the phone mic.
I also tried with MediaRecorder.AudioSource.MIC, DEFAULT, VOICE_COMMUNICATION