Skip to content

Commit

Permalink
Update to AndroidX Media3 1.5.0-rc01
Browse files Browse the repository at this point in the history
Update to AndroidX Media3 1.5.0-rc02
  • Loading branch information
MGaetan89 committed Nov 19, 2024
1 parent 3f6e6e1 commit 55e3c0f
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 74 deletions.
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ updates:
ignore:
- dependency-name: "com.comscore:*"
- dependency-name: "com.tagcommander.lib:*"
- dependency-name: "com.google.guava:*" # Guava is updated together with AndroidX Media3
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ androidx-core = "1.15.0"
androidx-datastore = "1.1.1"
androidx-fragment = "1.8.5"
androidx-lifecycle = "2.8.7"
androidx-media3 = "1.4.1"
androidx-media3 = "1.5.0-rc02"
androidx-navigation = "2.8.3"
androidx-paging = "3.3.2"
androidx-test-core = "1.6.1"
Expand All @@ -21,7 +21,7 @@ comscore = "6.11.1"
dependency-analysis-gradle-plugin = "2.4.2"
detekt = "1.23.7"
dokka = "2.0.0-Beta"
guava = "33.0.0-android"
guava = "33.3.1-android"
json = "20240303"
junit = "4.13.2"
kotlin = "2.0.21"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ internal class CommandersActStreaming(
?: C.LANGUAGE_UNDETERMINED

event.audioTrackLanguage = audioTrackLanguage

event.audioTrackHasAudioDescription = currentAudioTrack?.format?.hasAccessibilityRoles() ?: false
event.audioTrackHasAudioDescription = currentAudioTrack?.format?.hasAccessibilityRoles() == true
}

override fun onIsPlayingChanged(eventTime: EventTime, isPlaying: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ data class Playlist(val title: String, val items: List<DemoItem>, val descriptio
urn = "urn:srf:video:unknown",
description = "Content that does not exist"
),
DemoItem.URN(
DemoItem.URL(
title = "Custom MediaSource",
urn = "https://custom-media.ch/fondue",
uri = "https://custom-media.ch/fondue",
description = "Using a custom CustomMediaSource"
),
BlockedTimeRangeAssetLoader.DemoItemBlockedTimeRangeAtStartAndEnd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.exoplayer.source.MediaSource
import androidx.media3.exoplayer.source.preload.DefaultPreloadManager.Status
import androidx.media3.exoplayer.source.preload.DefaultPreloadManager.Status.STAGE_LOADED_TO_POSITION_MS
import androidx.media3.exoplayer.source.preload.DefaultPreloadManager.Status.STAGE_LOADED_FOR_DURATION_MS
import androidx.media3.exoplayer.source.preload.TargetPreloadStatusControl
import ch.srgssr.pillarbox.core.business.PillarboxExoPlayer
import ch.srgssr.pillarbox.core.business.source.SRGAssetLoader
Expand All @@ -36,6 +36,14 @@ class StoryViewModel(application: Application) : AndroidViewModel(application) {
private val mediaSourceFactory = PillarboxMediaSourceFactory(application).apply {
addAssetLoader(SRGAssetLoader(application))
}
private val loadControl = PillarboxLoadControl(
bufferDurations = PillarboxLoadControl.BufferDurations(
minBufferDuration = 5.seconds,
maxBufferDuration = 20.seconds,
bufferForPlayback = 500.milliseconds,
bufferForPlaybackAfterRebuffer = 1.seconds,
),
)
private val preloadManager = PillarboxPreloadManager(
context = application,
targetPreloadStatusControl = StoryPreloadStatusControl(),
Expand All @@ -44,17 +52,8 @@ class StoryViewModel(application: Application) : AndroidViewModel(application) {
parameters = parameters.buildUpon()
.setForceLowestBitrate(true)
.build()
}
)

private val loadControl = PillarboxLoadControl(
bufferDurations = PillarboxLoadControl.BufferDurations(
minBufferDuration = 5.seconds,
maxBufferDuration = 20.seconds,
bufferForPlayback = 500.milliseconds,
bufferForPlaybackAfterRebuffer = 1_000.milliseconds,
),
allocator = preloadManager.allocator,
},
loadControl = loadControl,
)

private var currentPage = C.INDEX_UNSET
Expand Down Expand Up @@ -160,8 +159,8 @@ class StoryViewModel(application: Application) : AndroidViewModel(application) {
val offset = abs(rankingData - currentPage)

return when (offset) {
1 -> Status(STAGE_LOADED_TO_POSITION_MS, 1.seconds.inWholeMicroseconds)
2, 3, 4 -> Status(STAGE_LOADED_TO_POSITION_MS, 1.milliseconds.inWholeMicroseconds)
1 -> Status(STAGE_LOADED_FOR_DURATION_MS, 1.seconds.inWholeMilliseconds)
2, 3, 4 -> Status(STAGE_LOADED_FOR_DURATION_MS, 1.milliseconds.inWholeMilliseconds)
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ class PillarboxExoPlayer internal constructor(
}
handleBlockedTimeRange(timeRange)
}

else -> Unit
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package ch.srgssr.pillarbox.player

import androidx.media3.common.C
import androidx.media3.common.Timeline
import androidx.media3.common.util.NullableType
import androidx.media3.exoplayer.DefaultLoadControl
import androidx.media3.exoplayer.LoadControl
import androidx.media3.exoplayer.Renderer
import androidx.media3.exoplayer.analytics.PlayerId
import androidx.media3.exoplayer.source.MediaSource
import androidx.media3.exoplayer.source.TrackGroupArray
Expand Down Expand Up @@ -46,6 +46,14 @@ class PillarboxLoadControl(
defaultLoadControl.onPrepared(playerId)
}

override fun onTracksSelected(
parameters: LoadControl.Parameters,
trackGroups: TrackGroupArray,
trackSelections: Array<out @NullableType ExoTrackSelection?>,
) {
defaultLoadControl.onTracksSelected(parameters, trackGroups, trackSelections)
}

override fun onStopped(playerId: PlayerId) {
defaultLoadControl.onStopped(playerId)
}
Expand All @@ -70,15 +78,12 @@ class PillarboxLoadControl(
return defaultLoadControl.shouldContinueLoading(parameters)
}

override fun onTracksSelected(
playerId: PlayerId,
override fun shouldContinuePreloading(
timeline: Timeline,
mediaPeriodId: MediaSource.MediaPeriodId,
renderers: Array<out Renderer>,
trackGroups: TrackGroupArray,
trackSelections: Array<out ExoTrackSelection>
) {
defaultLoadControl.onTracksSelected(playerId, timeline, mediaPeriodId, renderers, trackGroups, trackSelections)
bufferedDurationUs: Long,
): Boolean {
return defaultLoadControl.shouldContinuePreloading(timeline, mediaPeriodId, bufferedDurationUs)
}

override fun shouldStartPlayback(parameters: LoadControl.Parameters): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ import android.os.Looper
import android.os.Process
import androidx.media3.common.C
import androidx.media3.common.MediaItem
import androidx.media3.exoplayer.DefaultRendererCapabilitiesList
import androidx.media3.exoplayer.RendererCapabilitiesList
import androidx.media3.exoplayer.LoadControl
import androidx.media3.exoplayer.RenderersFactory
import androidx.media3.exoplayer.source.MediaSource
import androidx.media3.exoplayer.source.preload.DefaultPreloadManager
import androidx.media3.exoplayer.source.preload.DefaultPreloadManager.Status
import androidx.media3.exoplayer.source.preload.DefaultPreloadManager.Status.STAGE_LOADED_TO_POSITION_MS
import androidx.media3.exoplayer.source.preload.DefaultPreloadManager.Status.STAGE_LOADED_FOR_DURATION_MS
import androidx.media3.exoplayer.source.preload.TargetPreloadStatusControl
import androidx.media3.exoplayer.trackselection.TrackSelector
import androidx.media3.exoplayer.upstream.Allocator
import androidx.media3.exoplayer.upstream.BandwidthMeter
import androidx.media3.exoplayer.upstream.DefaultAllocator
import ch.srgssr.pillarbox.player.source.PillarboxMediaSourceFactory
import kotlin.math.abs
import kotlin.time.Duration.Companion.milliseconds
Expand All @@ -34,8 +32,8 @@ import kotlin.time.Duration.Companion.seconds
* @param mediaSourceFactory The [PillarboxMediaSourceFactory] to create each [MediaSource].
* @param trackSelector The [TrackSelector] for this preload manager.
* @param bandwidthMeter The [BandwidthMeter] for this preload manager.
* @param rendererCapabilitiesListFactory The [RendererCapabilitiesList.Factory] for this preload manager.
* @property allocator The [Allocator] for this preload manager. Have to be the same as the one used by the Player.
* @param renderersFactory The [RenderersFactory] for this preload manager.
* @param loadControl The [LoadControl] for this preload manager.
* @param playbackThread The [Thread] on which the players run. Its lifecycle is handled internally by [PillarboxPreloadManager].
*
* @see DefaultPreloadManager
Expand All @@ -46,10 +44,8 @@ class PillarboxPreloadManager(
mediaSourceFactory: PillarboxMediaSourceFactory = PillarboxMediaSourceFactory(context),
trackSelector: TrackSelector = PillarboxTrackSelector(context),
bandwidthMeter: BandwidthMeter = PillarboxBandwidthMeter(context),
rendererCapabilitiesListFactory: RendererCapabilitiesList.Factory = DefaultRendererCapabilitiesList.Factory(
PillarboxRenderersFactory(context)
),
val allocator: DefaultAllocator = DefaultAllocator(false, C.DEFAULT_BUFFER_SEGMENT_SIZE),
renderersFactory: RenderersFactory = PillarboxRenderersFactory(context),
loadControl: LoadControl = PillarboxLoadControl(),
private val playbackThread: HandlerThread = HandlerThread("PillarboxPreloadManager:Playback", Process.THREAD_PRIORITY_AUDIO),
) {
private val preloadManager: DefaultPreloadManager
Expand Down Expand Up @@ -82,15 +78,14 @@ class PillarboxPreloadManager(
playbackThread.start()
playbackLooper = playbackThread.looper
trackSelector.init({}, bandwidthMeter)
preloadManager = DefaultPreloadManager(
targetPreloadStatusControl ?: DefaultTargetPreloadStatusControl(),
mediaSourceFactory,
trackSelector,
bandwidthMeter,
rendererCapabilitiesListFactory,
allocator,
playbackLooper,
)
preloadManager = DefaultPreloadManager.Builder(context, targetPreloadStatusControl ?: DefaultTargetPreloadStatusControl())
.setMediaSourceFactory(mediaSourceFactory)
.setTrackSelectorFactory { trackSelector }
.setBandwidthMeter(bandwidthMeter)
.setRenderersFactory(renderersFactory)
.setLoadControl(loadControl)
.setPreloadLooper(playbackLooper)
.build()
}

/**
Expand Down Expand Up @@ -187,8 +182,8 @@ class PillarboxPreloadManager(
val offset = abs(rankingData - currentPlayingIndex)

return when (offset) {
1 -> Status(STAGE_LOADED_TO_POSITION_MS, 1.seconds.inWholeMicroseconds)
2, 3 -> Status(STAGE_LOADED_TO_POSITION_MS, 500.milliseconds.inWholeMicroseconds)
1 -> Status(STAGE_LOADED_FOR_DURATION_MS, 1.seconds.inWholeMilliseconds)
2, 3 -> Status(STAGE_LOADED_FOR_DURATION_MS, 500.milliseconds.inWholeMilliseconds)
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ open class PillarboxMediaController internal constructor() : PillarboxPlayer {
*/
@get:UnstableApi
val customLayout: ImmutableList<CommandButton>
get() = mediaController.getCustomLayout()
get() = mediaController.customLayout

/**
* Session extras
Expand Down Expand Up @@ -519,31 +519,10 @@ open class PillarboxMediaController internal constructor() : PillarboxPlayer {
mediaController.seekForward()
}

@UnstableApi
@Deprecated("Use #hasPreviousMediaItem() instead.", ReplaceWith("hasPreviousMediaItem()"))
override fun hasPrevious(): Boolean {
@Suppress("DEPRECATION")
return mediaController.hasPrevious()
}

@UnstableApi
@Deprecated("Use #hasPreviousMediaItem() instead.", ReplaceWith("hasPreviousMediaItem()"))
override fun hasPreviousWindow(): Boolean {
@Suppress("DEPRECATION")
return mediaController.hasPreviousWindow()
}

override fun hasPreviousMediaItem(): Boolean {
return mediaController.hasPreviousMediaItem()
}

@UnstableApi
@Deprecated("Use #seekToPreviousMediaItem() instead.", ReplaceWith("seekToPreviousMediaItem()"))
override fun previous() {
@Suppress("DEPRECATION")
mediaController.previous()
}

@UnstableApi
@Deprecated("Use #seekToPreviousMediaItem() instead.", ReplaceWith("seekToPreviousMediaItem()"))
override fun seekToPreviousWindow() {
Expand Down

0 comments on commit 55e3c0f

Please sign in to comment.