Audio Interactions
Speaker Interactions
Note: The camera should have already started streaming LiveView before making any interactions
To listen to whether the camera’s audio is played on the phone, The following can be used:
viewModelScope.launch {
client.isSpeakerEnabled.collectLatest { isEnabled ->
// isEnabled will report the current status of the speaker if its on or not.
}
}
To toggle the Speaker, The following can be used:
client.enableSpeaker(true)
Microphone Interactions
Note: The camera should have already started streaming LiveView before making any interactions
To listen to whether the phone microphone is captured and sent to the camera (this also switches the camera’s speaker on), The following can be used:
viewModelScope.launch {
client.isMicEnabled.collectLatest { isEnabled ->
// isEnabled will report the current status of the microphone if its on or not.
}
}
To toggle the Microphone, The following can be used:
client.enableMic(true)
The microphone hardware is only held while a stream is actually using it, so enableMic(false) releases it rather than leaving it open for the lifetime of the stream.
Telling the SDK when the app is in the foreground
The SDK assumes the app is in the foreground until told otherwise. Report the change from your Activity or process lifecycle observer so the microphone is released when the app is backgrounded and re-acquired when it returns; if you never call setAppInForeground(false), capture continues in the background:
override fun onStart() {
super.onStart()
InstaVision.setAppInForeground(true)
}
override fun onStop() {
super.onStop()
InstaVision.setAppInForeground(false)
}
Handing audio over to a call
If your app manages calls through its own ConnectionService or Telecom integration, tell the client to stop managing the audio mode so the two do not fight over the audio route:
client.setTelecomOwnsAudio(true)
Set it back to false once the call ends and the SDK should manage the audio route again.
Raw audio command
enableSpeaker / enableMic are what apps normally use. sendAudioCommandOnDataChannel(isEnabled) sends the camera-speaker on/off message that enableMic sends — without checking that the data channel is open. sendOverDataChannel(json) sends any other message and silently drops it if the channel is not open.