Skip to content

Commit

Permalink
Merge pull request #57 from muxinc/ajlb/feat/set-drm-type-by-default
Browse files Browse the repository at this point in the history
feat: set drm type by default
  • Loading branch information
andrewjl-mux authored Sep 18, 2024
2 parents fb0f54c + b95ac51 commit 4235293
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class CacheDatastoreInstrumentationTests {
@Test
fun testBasicInitialization() {
val datastore = CacheDatastore(appContext)
datastore.use { it.open() }
datastore.also { it.open() }

Assert.assertTrue(
"cache files dir should exist after open()",
Expand All @@ -92,7 +92,7 @@ class CacheDatastoreInstrumentationTests {
@Test
fun testCreateTempDownloadFile() {
val datastore = CacheDatastore(appContext)
datastore.use {
datastore.also {
it.open()

val url = URL("https://some.host.com/path1/path2/basename.ts")
Expand All @@ -115,7 +115,7 @@ class CacheDatastoreInstrumentationTests {

val datastore = CacheDatastore(appContext)
datastore.open()
datastore.use {
datastore.also {
// Write one file...
val oldTempFile = datastore.createTempDownloadFile(url)
BufferedOutputStream(FileOutputStream(oldTempFile)).use { it.write(oldFileData) }
Expand Down Expand Up @@ -144,7 +144,7 @@ class CacheDatastoreInstrumentationTests {
@Test
fun testWriteRecordReplacesOnKey() {
val datastore = CacheDatastore(appContext)
datastore.use {
datastore.also {
val originalRecord = FileRecord(
url = "url",
etag = "etag1",
Expand Down Expand Up @@ -192,7 +192,7 @@ class CacheDatastoreInstrumentationTests {
@Test
fun testReadRecord() {
fun testTheCase(url: String) {
CacheDatastore(appContext).use { datastore ->
CacheDatastore(appContext).also { datastore ->
val originalRecord = FileRecord(
url = url,
etag = "etag1",
Expand Down Expand Up @@ -223,7 +223,7 @@ class CacheDatastoreInstrumentationTests {
@Test
fun testReadLeastRecentFiles() {
val maxCacheSize = 5L
CacheDatastore(appContext, maxDiskSize = maxCacheSize).use { datastore ->
CacheDatastore(appContext, maxDiskSize = maxCacheSize).also { datastore ->
datastore.open()
// For this test, size "units" are like one digit.
// time "units" start in the 3-digit range and tick at ~10 units per call to fakeNow()
Expand Down Expand Up @@ -286,7 +286,7 @@ class CacheDatastoreInstrumentationTests {
val maxCacheSize = 5500L
val dummyFileSize = 1000L

CacheDatastore(appContext, maxDiskSize = maxCacheSize).use { datastore ->
CacheDatastore(appContext, maxDiskSize = maxCacheSize).also { datastore ->
datastore.open()
// time "units" start in the 3-digit range and tick at ~10 units per call to fakeNow()
var fakeLastAccess = 200L // increment by some amount when you need to
Expand Down
19 changes: 18 additions & 1 deletion library/src/main/java/com/mux/player/MuxPlayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import androidx.media3.datasource.DefaultDataSource
import androidx.media3.exoplayer.ExoPlayer
import com.mux.player.internal.cache.CacheController
import com.mux.stats.sdk.core.model.CustomerData
import com.mux.stats.sdk.core.model.CustomerViewData
import com.mux.stats.sdk.muxstats.MuxStatsSdkMedia3
import com.mux.player.internal.createLogcatLogger
import com.mux.player.internal.Logger
import com.mux.player.internal.createNoLogger
import com.mux.player.internal.Constants
import com.mux.player.media.MuxDataSource
import com.mux.player.media.MuxMediaSourceFactory
import com.mux.player.media.MediaItems
Expand Down Expand Up @@ -41,6 +43,7 @@ class MuxPlayer private constructor(
private val muxDataKey: String?,
private val logger: Logger,
private val muxCacheEnabled: Boolean = true,
private val didAddMonitoringData: Boolean = false,
context: Context,
initialCustomerData: CustomerData,
network: INetworkRequest? = null,
Expand Down Expand Up @@ -71,7 +74,18 @@ class MuxPlayer private constructor(
exoPlayer.addListener(object : Listener {
// more listener methods here if required
override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
//muxStats?.videoChange(CustomerVideoData())
// Check if a DRM token is set, set View Drm Type if it is
if (mediaItem?.requestMetadata?.extras?.getString(Constants.BUNDLE_DRM_TOKEN) != null && !didAddMonitoringData) {
val viewData = CustomerViewData()
// Assumes only widevine DRM playback is supported
// If playready support is added in future, update to select between widevine and playready
viewData.viewDrmType = Constants.VIEW_DRM_TYPE_WIDEVINE

// This doesn't overwrite other keys like view session ID to null
val customerData = CustomerData()
customerData.customerViewData = viewData
muxStats?.updateCustomerData(customerData)
}
}
})

Expand Down Expand Up @@ -138,6 +152,7 @@ class MuxPlayer private constructor(
private var enableSmartCache: Boolean = false
private var logger: Logger? = null
private var customerData: CustomerData = CustomerData()
private var didAddMonitoringData: Boolean = false
private var exoPlayerBinding: ExoPlayerBinding? = null
private var network: INetworkRequest? = null

Expand Down Expand Up @@ -191,6 +206,7 @@ class MuxPlayer private constructor(
@Suppress("unused")
fun addMonitoringData(customerData: CustomerData): Builder {
this.customerData.update(customerData)
this.didAddMonitoringData = true
return this
}

Expand Down Expand Up @@ -243,6 +259,7 @@ class MuxPlayer private constructor(
exoPlayer = this.playerBuilder.build(),
muxDataKey = this.dataEnvKey,
muxCacheEnabled = enableSmartCache,
didAddMonitoringData = this.didAddMonitoringData,
logger = logger ?: createNoLogger(),
initialCustomerData = customerData,
network = network,
Expand Down
2 changes: 2 additions & 0 deletions library/src/main/java/com/mux/player/internal/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ internal object Constants {
const val EXT_M4S = "m4s"
const val EXT_TS = "ts"

const val VIEW_DRM_TYPE_WIDEVINE = "widevine"

/**
* Can be rooted in cache or files dir on either internal or external storage
*/
Expand Down

0 comments on commit 4235293

Please sign in to comment.