Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion android/src/main/java/com/brentvatne/exoplayer/CMCDConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.brentvatne.exoplayer
import androidx.media3.common.MediaItem
import androidx.media3.exoplayer.upstream.CmcdConfiguration
import com.brentvatne.common.api.CMCDProps
import com.brentvatne.common.toolbox.DebugLog
import com.google.common.collect.ImmutableListMultimap

class CMCDConfig(private val props: CMCDProps) {
Expand All @@ -15,9 +16,21 @@ class CMCDConfig(private val props: CMCDProps) {
object : CmcdConfiguration.RequestConfig {
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> =
ImmutableListMultimap.builder<String, String>().apply {
addFormattedData(this, CmcdConfiguration.KEY_CMCD_OBJECT, props.cmcdObject)
Expand Down
Loading