Skip to content

Commit

Permalink
Load control test
Browse files Browse the repository at this point in the history
  • Loading branch information
saravr committed Jun 11, 2024
1 parent 67d37df commit e2e440b
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.scribd.armadillo.playback

import com.google.android.exoplayer2.analytics.AnalyticsListener
import com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime
import com.google.android.exoplayer2.source.LoadEventInfo
import com.google.android.exoplayer2.source.MediaLoadData
import com.google.android.exoplayer2.util.Log
import java.io.IOException
import java.lang.Exception

class ArmadilloAnalyticsListener : AnalyticsListener {
override fun onLoadStarted(
eventTime: EventTime,
loadEventInfo: LoadEventInfo,
mediaLoadData: MediaLoadData
) {
// Called when a media load starts
Log.e(TAG, "Load started: ${loadEventInfo.describe()}")
}

override fun onLoadCompleted(
eventTime: EventTime,
loadEventInfo: LoadEventInfo,
mediaLoadData: MediaLoadData
) {
// Called when a media load completes
Log.e(TAG, "Load completed: ${loadEventInfo.describe()}")
}

override fun onLoadCanceled(
eventTime: EventTime,
loadEventInfo: LoadEventInfo,
mediaLoadData: MediaLoadData
) {
// Called when a media load is canceled
Log.e(TAG, "Load canceled: ${loadEventInfo.describe()}")
}

override fun onLoadError(
eventTime: EventTime,
loadEventInfo: LoadEventInfo,
mediaLoadData: MediaLoadData,
error: IOException,
wasCanceled: Boolean
) {
// Called when a media load encounters an error
Log.e(TAG, "Load error: ${loadEventInfo.describeWithError(error, wasCanceled)}")
}

companion object {
private const val TAG = "ArmListener"
}
}

fun LoadEventInfo.describe(): String {
return "${dataSpec.uri} pos: ${dataSpec.position}, len: ${dataSpec.length}"
}

fun LoadEventInfo.describeWithError(exception: Exception, wasCanceled: Boolean): String {
return "ERR: ${exception.message}: wasCanceled: $wasCanceled, ${dataSpec.uri} pos: ${dataSpec.position}, len: ${dataSpec.length}"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.scribd.armadillo.playback

import android.content.Context
import android.util.Log
import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.DefaultLoadControl
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.RenderersFactory
import com.google.android.exoplayer2.audio.AudioAttributes
Expand Down Expand Up @@ -41,12 +43,24 @@ internal fun ExoPlayer.playerDuration(): Milliseconds? = if (duration == C.TIME_
*
* We provide our own renderers factory so that Proguard can remove any non-audio rendering code.
*/
internal fun createExoplayerInstance(context: Context, attributes: AudioAttributes): ExoPlayer =
ExoPlayer.Builder(context, createRenderersFactory(context))
internal fun createExoplayerInstance(context: Context, attributes: AudioAttributes): ExoPlayer {
val loadControl = DefaultLoadControl.Builder()
.setBufferDurationsMs(
20000,
120 * 60 * 1000, // 2hrs??
5000,
5000,
)
.build()

Log.e("ExoplayerExt", "++++ USING LOAD CONTROL 2hrs")
return ExoPlayer.Builder(context, createRenderersFactory(context))
.setLoadControl(loadControl)
.build().apply {
setAudioAttributes(attributes, true)
addAnalyticsListener(ArmadilloAnalyticsListener())
}

}
internal fun createRenderersFactory(context: Context): RenderersFactory =
RenderersFactory { eventHandler, _, audioRendererEventListener, _, _ ->
// Default audio sink taken from DefaultRenderersFactory. We need to provide it in order to enable offloading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ internal class PlayerEventListener : Player.Listener {
@Inject
internal lateinit var stateModifier: StateStore.Modifier

override fun onEvents(player: Player, events: Player.Events) {
super.onEvents(player, events)
Log.e(TAG, "ExoPlayer events: ${events.describe()}")
}

override fun onPlayerError(error: PlaybackException) {
val exception = (error as ExoPlaybackException).toArmadilloException()
stateModifier.dispatch(ErrorAction(exception))
Expand Down Expand Up @@ -80,4 +85,12 @@ internal class PlayerEventListener : Player.Listener {
else -> "unknown"
}
}
}
}

fun Player.Events.describe(): String {
val flags = mutableListOf<Int>()
repeat(size()) {
flags.add(get(it))
}
return flags.joinToString()
}

0 comments on commit e2e440b

Please sign in to comment.