fix(android): add helper to avoid type error (#4257)

* fix(android): add helper to avoid type error
This commit is contained in:
Olivier Bouillet 2024-10-24 11:43:10 +02:00 committed by GitHub
parent 21e2da3bfb
commit 3b4bfd3936
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,6 +3,7 @@ package com.brentvatne.exoplayer
import androidx.media3.common.MediaItem import androidx.media3.common.MediaItem
import androidx.media3.exoplayer.upstream.CmcdConfiguration import androidx.media3.exoplayer.upstream.CmcdConfiguration
import com.brentvatne.common.api.CMCDProps import com.brentvatne.common.api.CMCDProps
import com.brentvatne.common.toolbox.DebugLog
import com.google.common.collect.ImmutableListMultimap import com.google.common.collect.ImmutableListMultimap
class CMCDConfig(private val props: CMCDProps) { class CMCDConfig(private val props: CMCDProps) {
@ -15,9 +16,21 @@ class CMCDConfig(private val props: CMCDProps) {
object : CmcdConfiguration.RequestConfig { object : CmcdConfiguration.RequestConfig {
override fun getCustomData(): ImmutableListMultimap<String, String> = buildCustomData() override fun getCustomData(): ImmutableListMultimap<String, String> = buildCustomData()
}, },
props.mode intToCmcdMode(props.mode)
) )
private fun intToCmcdMode(mode: Int): Int =
when (mode) {
0 -> CmcdConfiguration.MODE_REQUEST_HEADER
1 -> CmcdConfiguration.MODE_QUERY_PARAMETER
else -> {
DebugLog.e("CMCDConfig", "Unsupported mode: $mode, fallback on MODE_REQUEST_HEADER")
CmcdConfiguration.MODE_REQUEST_HEADER
}
}
private fun buildCustomData(): ImmutableListMultimap<String, String> = private fun buildCustomData(): ImmutableListMultimap<String, String> =
ImmutableListMultimap.builder<String, String>().apply { ImmutableListMultimap.builder<String, String>().apply {
addFormattedData(this, CmcdConfiguration.KEY_CMCD_OBJECT, props.cmcdObject) addFormattedData(this, CmcdConfiguration.KEY_CMCD_OBJECT, props.cmcdObject)