Avoid creating a Json instance many times.
This commit is contained in:
parent
241a968d66
commit
ab35235bae
1 changed files with 8 additions and 5 deletions
|
|
@ -44,6 +44,13 @@ class WebViewAudioManager(
|
||||||
private val coroutineScope: CoroutineScope,
|
private val coroutineScope: CoroutineScope,
|
||||||
private val onInvalidAudioDeviceAdded: (InvalidAudioDeviceReason) -> Unit,
|
private val onInvalidAudioDeviceAdded: (InvalidAudioDeviceReason) -> Unit,
|
||||||
) {
|
) {
|
||||||
|
private val json by lazy {
|
||||||
|
Json {
|
||||||
|
encodeDefaults = true
|
||||||
|
explicitNulls = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to disable bluetooth audio devices. This must be done on Android versions lower than Android 12,
|
* Whether to disable bluetooth audio devices. This must be done on Android versions lower than Android 12,
|
||||||
* since the WebView approach breaks when using the legacy Bluetooth audio APIs.
|
* since the WebView approach breaks when using the legacy Bluetooth audio APIs.
|
||||||
|
|
@ -308,11 +315,7 @@ class WebViewAudioManager(
|
||||||
devices: List<SerializableAudioDevice> = listAudioDevices().map(SerializableAudioDevice::fromAudioDeviceInfo),
|
devices: List<SerializableAudioDevice> = listAudioDevices().map(SerializableAudioDevice::fromAudioDeviceInfo),
|
||||||
) {
|
) {
|
||||||
Timber.d("Updating available audio devices")
|
Timber.d("Updating available audio devices")
|
||||||
val jsonSerializer = Json {
|
val deviceList = json.encodeToString(devices)
|
||||||
encodeDefaults = true
|
|
||||||
explicitNulls = false
|
|
||||||
}
|
|
||||||
val deviceList = jsonSerializer.encodeToString(devices)
|
|
||||||
webView.evaluateJavascript("controls.setAvailableOutputDevices($deviceList);", {
|
webView.evaluateJavascript("controls.setAvailableOutputDevices($deviceList);", {
|
||||||
Timber.d("Audio: setAvailableOutputDevices result: $it")
|
Timber.d("Audio: setAvailableOutputDevices result: $it")
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue