Skip to content

Commit

Permalink
Update dependencies move extensions (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
StaehliJ authored Oct 30, 2023
1 parent b84fbf7 commit 60e431c
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 74 deletions.
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
accompanist = "0.33.0-alpha"
activityCompose = "1.8.0"
androidGradlePlugin = "8.1.2"
dataProvider = "0.5.0"
dataProvider = "0.6.2"
kotlinPlugin = "1.9.10"
detekt = "1.22.0" # https://github.com/detekt/detekt
kotlinxSerializationJson = "1.6.0"
Expand All @@ -23,12 +23,12 @@ navigationCompose = "2.7.4"
pagingCompose = "3.2.1"
okhttp = "4.10.0"
retrofit2KotlinxSerializationConverter = "1.0.0"
tagCommanderCore = "5.4.0"
tagCommanderServerSide = "5.5.0"
tagCommanderCore = "5.4.1"
tagCommanderServerSide = "5.5.1"
comscore = "6.10.0"
androidxComposeBom = "2023.10.00"
androidxComposeBom = "2023.10.01"
leanback = "1.0.0"
tvCompose = "1.0.0-alpha09"
tvCompose = "1.0.0-alpha10"
androidx-test-ext-junit = "1.1.5"
appcompat = "1.6.1"
material = "1.10.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import ch.srgssr.pillarbox.core.business.tracker.SRGEventLoggerTracker
import ch.srgssr.pillarbox.core.business.tracker.commandersact.CommandersActTracker
import ch.srgssr.pillarbox.core.business.tracker.comscore.ComScoreTracker
import ch.srgssr.pillarbox.player.data.MediaItemSource
import ch.srgssr.pillarbox.player.getMediaItemTrackerData
import ch.srgssr.pillarbox.player.setTrackerData
import ch.srgssr.pillarbox.player.extension.getMediaItemTrackerData
import ch.srgssr.pillarbox.player.extension.setTrackerData
import io.ktor.client.plugins.ClientRequestException
import kotlinx.serialization.SerializationException
import java.io.IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import androidx.media3.common.util.Size
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.analytics.AnalyticsListener
import ch.srgssr.pillarbox.analytics.BuildConfig
import ch.srgssr.pillarbox.player.getPlaybackSpeed
import ch.srgssr.pillarbox.player.extension.getPlaybackSpeed
import ch.srgssr.pillarbox.player.tracker.MediaItemTracker
import ch.srgssr.pillarbox.player.utils.DebugLogger
import com.comscore.streaming.ContentMetadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import androidx.media3.common.Player
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.Icon
import androidx.tv.material3.IconButton
import ch.srgssr.pillarbox.player.canSeekBack
import ch.srgssr.pillarbox.player.canSeekForward
import ch.srgssr.pillarbox.player.canSeekToNext
import ch.srgssr.pillarbox.player.canSeekToPrevious
import ch.srgssr.pillarbox.player.extension.canSeekBack
import ch.srgssr.pillarbox.player.extension.canSeekForward
import ch.srgssr.pillarbox.player.extension.canSeekToNext
import ch.srgssr.pillarbox.player.extension.canSeekToPrevious
import ch.srgssr.pillarbox.ui.extension.availableCommandsAsState
import ch.srgssr.pillarbox.ui.extension.isPlayingAsState
import ch.srgssr.pillarbox.ui.widget.DelayedVisibilityState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import androidx.media3.common.Timeline
import androidx.media3.common.VideoSize
import ch.srgssr.pillarbox.demo.shared.data.DemoItem
import ch.srgssr.pillarbox.demo.shared.di.PlayerModule
import ch.srgssr.pillarbox.player.toRational
import ch.srgssr.pillarbox.player.extension.toRational
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.media3.common.Player
import ch.srgssr.pillarbox.player.canPlayPause
import ch.srgssr.pillarbox.player.canSeekBack
import ch.srgssr.pillarbox.player.canSeekForward
import ch.srgssr.pillarbox.player.canSeekToNext
import ch.srgssr.pillarbox.player.canSeekToPrevious
import ch.srgssr.pillarbox.player.extension.canPlayPause
import ch.srgssr.pillarbox.player.extension.canSeekBack
import ch.srgssr.pillarbox.player.extension.canSeekForward
import ch.srgssr.pillarbox.player.extension.canSeekToNext
import ch.srgssr.pillarbox.player.extension.canSeekToPrevious
import ch.srgssr.pillarbox.ui.extension.availableCommandsAsState
import ch.srgssr.pillarbox.ui.extension.isPlayingAsState

Expand All @@ -40,14 +40,13 @@ fun PlayerPlaybackRow(
modifier: Modifier = Modifier,
) {
val availableCommands = player.availableCommandsAsState()
val togglePlaybackFunction = remember(player) {
val toggleOrResumePlayback = remember(player) {
{
if (player.playbackState == Player.STATE_IDLE) {
player.prepare()
}
if (player.playbackState == Player.STATE_ENDED) {
player.seekToDefaultPosition()
player.play()
} else {
player.playWhenReady = !player.playWhenReady
}
Expand All @@ -71,7 +70,7 @@ fun PlayerPlaybackRow(
isEnabled = availableCommands.canPlayPause(),
icon = if (isPlaying) Icons.Default.Pause else Icons.Default.PlayArrow,
contentDescription = if (isPlaying) "Pause" else "Play",
onClick = togglePlaybackFunction
onClick = toggleOrResumePlayback
)
Button(
icon = Icons.Default.FastForward,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import androidx.lifecycle.viewModelScope
import androidx.media3.session.MediaBrowser
import androidx.media3.session.SessionToken
import ch.srgssr.pillarbox.demo.service.DemoMediaLibraryService
import ch.srgssr.pillarbox.player.RATIONAL_ONE
import ch.srgssr.pillarbox.player.toRational
import ch.srgssr.pillarbox.player.extension.RATIONAL_ONE
import ch.srgssr.pillarbox.player.extension.toRational
import ch.srgssr.pillarbox.player.videoSizeAsFlow
import com.google.common.util.concurrent.MoreExecutors
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.media3.common.C
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata
import androidx.media3.common.Player
Expand Down Expand Up @@ -80,11 +79,11 @@ fun PlaylistView(
onRemoveItemIndex = player::removeMediaItem,
onMoveItemIndex = player::moveMediaItem,
onItemClick = { _: MediaItem, index: Int ->
player.seekTo(index, C.TIME_UNSET)
if (player.playbackState == Player.STATE_IDLE || player.playerError != null) {
player.seekToDefaultPosition(index)
player.play()
if (player.playbackState == Player.STATE_IDLE) {
player.prepare()
}
player.play()
},
onAddToPlaylistClick = {
addItemDialogState.value = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import androidx.media3.common.Player
import ch.srgssr.pillarbox.player.extension.audio
import ch.srgssr.pillarbox.player.extension.getPlaybackSpeed
import ch.srgssr.pillarbox.player.extension.text
import ch.srgssr.pillarbox.player.getCurrentTracksAsFlow
import ch.srgssr.pillarbox.player.getPlaybackSpeed
import ch.srgssr.pillarbox.player.getPlaybackSpeedAsFlow
import ch.srgssr.pillarbox.player.getTrackSelectionParametersAsFlow
import kotlinx.coroutines.flow.SharingStarted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package ch.srgssr.pillarbox.player

import android.content.Context
import androidx.media3.common.MediaItem
import androidx.media3.common.PlaybackException
import androidx.media3.common.PlaybackParameters
import androidx.media3.common.Player
Expand All @@ -22,6 +21,7 @@ import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
import androidx.media3.exoplayer.upstream.DefaultBandwidthMeter
import androidx.media3.exoplayer.util.EventLogger
import ch.srgssr.pillarbox.player.data.MediaItemSource
import ch.srgssr.pillarbox.player.extension.getPlaybackSpeed
import ch.srgssr.pillarbox.player.extension.setPreferredAudioRoleFlagsToAccessibilityManagerSettings
import ch.srgssr.pillarbox.player.extension.setSeekIncrements
import ch.srgssr.pillarbox.player.source.PillarboxMediaSourceFactory
Expand Down Expand Up @@ -162,39 +162,6 @@ class PillarboxPlayer internal constructor(
}
}

/**
* Get a snapshot of the current media items
*/
fun Player.getCurrentMediaItems(): List<MediaItem> {
if (mediaItemCount == 0) {
return emptyList()
}
val count = mediaItemCount
return ArrayList<MediaItem>(count).apply {
for (i in 0 until count) {
add(getMediaItemAt(i))
}
}
}

/**
* Get playback speed
*
* @return [Player.getPlaybackParameters] speed
*/
fun Player.getPlaybackSpeed(): Float {
return playbackParameters.speed
}

/**
* Current position percent
*
* @return the current position in percent [0,1].
*/
fun Player.currentPositionPercentage(): Float {
return currentPosition / duration.coerceAtLeast(1).toFloat()
}

/**
* Return if the playback [speed] is possible at [position].
* Always return true for none live content or if [Player.getCurrentTimeline] is empty.
Expand All @@ -212,10 +179,6 @@ fun Player.isPlaybackSpeedPossibleAtPosition(position: Long, speed: Float, windo
return window.isPlaybackSpeedPossibleAtPosition(position, speed)
}

internal fun Window.isAtDefaultPosition(positionMs: Long): Boolean {
return positionMs >= defaultPositionMs
}

internal fun Window.isPlaybackSpeedPossibleAtPosition(positionMs: Long, playbackSpeed: Float): Boolean {
return when {
!isLive() || playbackSpeed == NormalSpeed -> true
Expand All @@ -225,4 +188,8 @@ internal fun Window.isPlaybackSpeedPossibleAtPosition(positionMs: Long, playback
}
}

internal fun Window.isAtDefaultPosition(positionMs: Long): Boolean {
return positionMs >= defaultPositionMs
}

private const val NormalSpeed = 1.0f
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import androidx.media3.common.Timeline
import androidx.media3.common.TrackSelectionParameters
import androidx.media3.common.Tracks
import androidx.media3.common.VideoSize
import ch.srgssr.pillarbox.player.extension.computeAspectRatio
import ch.srgssr.pillarbox.player.extension.getCurrentMediaItems
import ch.srgssr.pillarbox.player.extension.getPlaybackSpeed
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.ProducerScope
import kotlinx.coroutines.channels.awaitClose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2023. SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.player
package ch.srgssr.pillarbox.player.extension

import androidx.media3.common.MediaItem
import ch.srgssr.pillarbox.player.tracker.MediaItemTrackerData
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2023. SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.player.extension

import androidx.media3.common.MediaItem
import androidx.media3.common.Player

/**
* Resume playback
*/
fun Player.startPlayback() {
when (playbackState) {
Player.STATE_IDLE -> {
prepare()
}

Player.STATE_ENDED -> {
seekToDefaultPosition()
}

else -> {
// Nothing
}
}
play()
}

/**
* Get a snapshot of the current media items
*/
fun Player.getCurrentMediaItems(): List<MediaItem> {
if (mediaItemCount == 0) {
return emptyList()
}
val count = mediaItemCount
return ArrayList<MediaItem>(count).apply {
for (i in 0 until count) {
add(getMediaItemAt(i))
}
}
}

/**
* Get playback speed
*
* @return [Player.getPlaybackParameters] speed
*/
fun Player.getPlaybackSpeed(): Float {
return playbackParameters.speed
}

/**
* Current position percent
*
* @return the current position in percent [0,1].
*/
fun Player.currentPositionPercentage(): Float {
return currentPosition / duration.coerceAtLeast(1).toFloat()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
@file:Suppress("unused")

package ch.srgssr.pillarbox.player
package ch.srgssr.pillarbox.player.extension

import androidx.media3.common.Player

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2023. SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.player
package ch.srgssr.pillarbox.player.extension

import android.util.Rational
import androidx.media3.common.VideoSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.media3.common.Timeline.Window
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.analytics.AnalyticsListener
import androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime
import ch.srgssr.pillarbox.player.getMediaItemTrackerDataOrNull
import ch.srgssr.pillarbox.player.extension.getMediaItemTrackerDataOrNull
import ch.srgssr.pillarbox.player.utils.DebugLogger
import ch.srgssr.pillarbox.player.utils.StringUtil

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

import androidx.media3.common.VideoSize
import ch.srgssr.pillarbox.player.extension.computeAspectRatio
import org.junit.Assert
import org.junit.Test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.remember
import androidx.media3.common.Player
import ch.srgssr.pillarbox.player.availableCommandsAsFlow
import ch.srgssr.pillarbox.player.canSeek
import ch.srgssr.pillarbox.player.currentPositionAsFlow
import ch.srgssr.pillarbox.player.currentPositionPercentage
import ch.srgssr.pillarbox.player.extension.canSeek
import ch.srgssr.pillarbox.player.extension.currentPositionPercentage
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collectLatest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import ch.srgssr.pillarbox.player.availableCommandsAsFlow
import ch.srgssr.pillarbox.player.currentMediaMetadataAsFlow
import ch.srgssr.pillarbox.player.currentPositionAsFlow
import ch.srgssr.pillarbox.player.durationAsFlow
import ch.srgssr.pillarbox.player.extension.getCurrentMediaItems
import ch.srgssr.pillarbox.player.extension.getPlaybackSpeed
import ch.srgssr.pillarbox.player.getAspectRatioAsFlow
import ch.srgssr.pillarbox.player.getCurrentMediaItemIndexAsFlow
import ch.srgssr.pillarbox.player.getCurrentMediaItems
import ch.srgssr.pillarbox.player.getCurrentMediaItemsAsFlow
import ch.srgssr.pillarbox.player.getPlaybackSpeed
import ch.srgssr.pillarbox.player.getPlaybackSpeedAsFlow
import ch.srgssr.pillarbox.player.isPlayingAsFlow
import ch.srgssr.pillarbox.player.mediaItemCountAsFlow
Expand Down

0 comments on commit 60e431c

Please sign in to comment.