Skip to content

Commit

Permalink
Rename to PillarboxExoPlayer (#765)
Browse files Browse the repository at this point in the history
Co-authored-by: Gaëtan Muller <[email protected]>
  • Loading branch information
StaehliJ and MGaetan89 authored Oct 25, 2024
1 parent 0ae1ba7 commit 0cc373a
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ import kotlin.time.Duration.Companion.seconds
* @param context The [Context].
* @param builder The builder.
* @receiver [SRG.Builder].
* @return The configured [PillarboxExoplayer] for SRG SSR.
* @return The configured [PillarboxExoPlayer] for SRG SSR.
*/
@Suppress("FunctionName")
@PillarboxDsl
fun PillarboxExoplayer(
fun PillarboxExoPlayer(
context: Context,
builder: SRG.Builder.() -> Unit = {},
): PillarboxExoPlayer {
return SRG.create()
.apply(builder)
.create(context)
return PillarboxExoPlayer(context, SRG, builder)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ch.srgssr.pillarbox.analytics.commandersact.MediaEventType.Seek
import ch.srgssr.pillarbox.analytics.commandersact.MediaEventType.Stop
import ch.srgssr.pillarbox.analytics.commandersact.MediaEventType.Uptime
import ch.srgssr.pillarbox.analytics.commandersact.TCMediaEvent
import ch.srgssr.pillarbox.core.business.PillarboxExoplayer
import ch.srgssr.pillarbox.core.business.PillarboxExoPlayer
import ch.srgssr.pillarbox.core.business.SRGMediaItem
import ch.srgssr.pillarbox.core.business.utils.LocalMediaCompositionWithFallbackService
import ch.srgssr.pillarbox.player.test.utils.TestPillarboxRunHelper
Expand Down Expand Up @@ -70,7 +70,7 @@ class CommandersActTrackerIntegrationTest {

val context = ApplicationProvider.getApplicationContext<Context>()
val mediaCompositionWithFallbackService = LocalMediaCompositionWithFallbackService(context)
player = PillarboxExoplayer(context) {
player = PillarboxExoPlayer(context) {
srgAssetLoader(context) {
mediaCompositionService(mediaCompositionWithFallbackService)
commanderActTrackerFactory(CommandersActTracker.Factory(commandersAct = commandersAct, coroutineContext = testDispatcher))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import ch.srgssr.pillarbox.analytics.BuildConfig
import ch.srgssr.pillarbox.core.business.PillarboxExoplayer
import ch.srgssr.pillarbox.core.business.PillarboxExoPlayer
import ch.srgssr.pillarbox.core.business.SRGMediaItem
import ch.srgssr.pillarbox.core.business.utils.LocalMediaCompositionWithFallbackService
import ch.srgssr.pillarbox.player.tracker.MediaItemTracker
Expand Down Expand Up @@ -57,7 +57,7 @@ class ComScoreTrackerIntegrationTest {
}
val context = ApplicationProvider.getApplicationContext<Context>()
val mediaCompositionWithFallbackService = LocalMediaCompositionWithFallbackService(context)
player = PillarboxExoplayer(context) {
player = PillarboxExoPlayer(context) {
clock(clock)
coroutineContext(EmptyCoroutineContext)
srgAssetLoader(context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.content.Context
import ch.srg.dataProvider.integrationlayer.dependencies.modules.IlServiceModule
import ch.srg.dataProvider.integrationlayer.dependencies.modules.OkHttpModule
import ch.srgssr.dataprovider.paging.DataProviderPaging
import ch.srgssr.pillarbox.core.business.PillarboxExoplayer
import ch.srgssr.pillarbox.core.business.PillarboxExoPlayer
import ch.srgssr.pillarbox.core.business.integrationlayer.service.IlHost
import ch.srgssr.pillarbox.demo.shared.source.BlockedTimeRangeAssetLoader
import ch.srgssr.pillarbox.demo.shared.source.CustomAssetLoader
Expand All @@ -27,7 +27,7 @@ object PlayerModule {
* Provide default player that allow to play urls and urns content from the SRG
*/
fun provideDefaultPlayer(context: Context): PillarboxExoPlayer {
return PillarboxExoplayer(context = context) {
return PillarboxExoPlayer(context = context) {
+CustomAssetLoader(context)
+BlockedTimeRangeAssetLoader(context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import androidx.media3.common.Player
import ch.srgssr.pillarbox.core.business.PillarboxExoplayer
import ch.srgssr.pillarbox.core.business.PillarboxExoPlayer
import ch.srgssr.pillarbox.demo.shared.data.DemoItem
import ch.srgssr.pillarbox.player.asset.timeRange.Chapter
import ch.srgssr.pillarbox.player.currentMediaMetadataAsFlow
Expand All @@ -30,7 +30,7 @@ class ChaptersShowcaseViewModel(application: Application) : AndroidViewModel(app
/**
* Player
*/
val player: Player = PillarboxExoplayer(application)
val player: Player = PillarboxExoPlayer(application)

/**
* Progress tracker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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.TargetPreloadStatusControl
import ch.srgssr.pillarbox.core.business.PillarboxExoplayer
import ch.srgssr.pillarbox.core.business.PillarboxExoPlayer
import ch.srgssr.pillarbox.core.business.source.SRGAssetLoader
import ch.srgssr.pillarbox.demo.shared.data.Playlist
import ch.srgssr.pillarbox.player.PillarboxExoPlayer
Expand Down Expand Up @@ -61,7 +61,7 @@ class StoryViewModel(application: Application) : AndroidViewModel(application) {

private val players = SparseArray<PillarboxExoPlayer>(PLAYERS_COUNT).apply {
for (i in 0 until PLAYERS_COUNT) {
val player = PillarboxExoplayer(application) {
val player = PillarboxExoPlayer(application) {
playbackLooper(preloadManager.playbackLooper)
loadControl(loadControl)
}.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import ch.srgssr.pillarbox.core.business.exception.BlockReasonException
import ch.srgssr.pillarbox.core.business.source.SRGAssetLoader
import ch.srgssr.pillarbox.demo.shared.data.DemoItem
import ch.srgssr.pillarbox.player.Default
import ch.srgssr.pillarbox.player.PillarboxExoPlayer
import ch.srgssr.pillarbox.player.asset.Asset
import ch.srgssr.pillarbox.player.asset.AssetLoader
Expand Down Expand Up @@ -42,7 +43,7 @@ class ContentNotYetAvailableViewModel(application: Application) : AndroidViewMod
/**
* Player
*/
val player: PillarboxExoPlayer = PillarboxExoPlayer(application) {
val player: PillarboxExoPlayer = PillarboxExoPlayer(application, Default) {
+AlwaysStartDateBlockedAssetLoader(application)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.compose.LifecycleStartEffect
import androidx.media3.common.Player
import ch.srgssr.pillarbox.core.business.PillarboxExoplayer
import ch.srgssr.pillarbox.core.business.PillarboxExoPlayer
import ch.srgssr.pillarbox.demo.R
import ch.srgssr.pillarbox.demo.shared.data.DemoItem
import ch.srgssr.pillarbox.demo.ui.player.controls.PlayerPlaybackRow
Expand All @@ -47,7 +47,7 @@ import ch.srgssr.pillarbox.ui.widget.player.PlayerSurface
fun SmoothSeekingShowcase() {
val context = LocalContext.current
val player = remember {
PillarboxExoplayer(context).apply {
PillarboxExoPlayer(context).apply {
addMediaItem(DemoItem.UnifiedStreamingOnDemand_Dash_TrickPlay.toMediaItem())
addMediaItem(DemoItem.UnifiedStreamingOnDemandTrickplay.toMediaItem())
addMediaItem(DemoItem.UnifiedStreamingOnDemand_Dash_FragmentedMP4.toMediaItem())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class IsPlayingAllTypeOfContentTest {
val atomicPlayer = AtomicReference<PillarboxExoPlayer>()
val waitIsPlaying = WaitIsPlaying()
getInstrumentation().runOnMainSync {
val player = PillarboxExoPlayer(appContext)
val player = PillarboxExoPlayer(appContext, Default)
atomicPlayer.set(player)
player.addMediaItem(MediaItem.fromUri(urlToTest))
player.addListener(waitIsPlaying)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,20 @@ import kotlin.coroutines.CoroutineContext
/**
* Create a new instance of [PillarboxExoPlayer].
*
* @param Builder The type of the [PillarboxBuilder].
* @param context The [Context].
* @param type The [PlayerConfig].
* @param builder The builder.
*
* @return A new instance of [PillarboxExoPlayer].
*/
@PillarboxDsl
fun PillarboxExoPlayer(
fun <Builder : PillarboxBuilder> PillarboxExoPlayer(
context: Context,
builder: Default.Builder.() -> Unit = {},
type: PlayerConfig<Builder>,
builder: Builder.() -> Unit = {},
): PillarboxExoPlayer {
return Default.create()
return type.create()
.apply(builder)
.create(context)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.player

import android.content.Context
import androidx.media3.exoplayer.DefaultLoadControl
import androidx.media3.test.utils.FakeClock
import androidx.test.core.app.ApplicationProvider
import kotlin.coroutines.EmptyCoroutineContext

/**
* Pillarbox ExoPlayer
*
* @param context The [Context], by default [ApplicationProvider.getApplicationContext]
* @param block The block to further configure the [PillarboxExoPlayer].
* @return [PillarboxExoPlayer] configured for tests.
*/
@PillarboxDsl
fun PillarboxExoPlayer(context: Context = ApplicationProvider.getApplicationContext(), block: Default.Builder.() -> Unit = {}): PillarboxExoPlayer {
return PillarboxExoPlayer(context, Default) {
loadControl(DefaultLoadControl())
clock(FakeClock(true))
coroutineContext(EmptyCoroutineContext)
block()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@
*/
package ch.srgssr.pillarbox.player

import android.content.Context
import android.os.Looper
import androidx.media3.common.C
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.exoplayer.DefaultLoadControl
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.test.utils.FakeClock
import androidx.media3.test.utils.robolectric.TestPlayerRunHelper
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import app.cash.turbine.test
import kotlinx.coroutines.test.runTest
import org.junit.runner.RunWith
import org.robolectric.Shadows.shadowOf
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
Expand All @@ -33,13 +28,7 @@ class PlayerCallbackFlowTest {

@BeforeTest
fun setUp() {
val context = ApplicationProvider.getApplicationContext<Context>()

player = PillarboxExoPlayer(context) {
loadControl(DefaultLoadControl())
clock(FakeClock(true))
coroutineContext(EmptyCoroutineContext)
}.apply {
player = PillarboxExoPlayer().apply {
prepare()
play()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
*/
package ch.srgssr.pillarbox.player.analytics

import android.content.Context
import android.os.Looper
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.exoplayer.DefaultLoadControl
import androidx.media3.test.utils.FakeClock
import androidx.media3.test.utils.robolectric.TestPlayerRunHelper
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.srgssr.pillarbox.player.PillarboxExoPlayer
import ch.srgssr.pillarbox.player.analytics.metrics.MetricsCollector
Expand All @@ -24,7 +20,6 @@ import io.mockk.slot
import io.mockk.verify
import org.junit.runner.RunWith
import org.robolectric.Shadows.shadowOf
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
Expand All @@ -43,13 +38,8 @@ class MetricsCollectorTest {

@BeforeTest
fun setUp() {
val context = ApplicationProvider.getApplicationContext<Context>()
metricsListener = mockk(relaxed = true)
player = PillarboxExoPlayer(context) {
loadControl(DefaultLoadControl())
clock(FakeClock(true))
coroutineContext(EmptyCoroutineContext)
}
player = PillarboxExoPlayer()
player.metricsCollector.addListener(metricsListener)
player.prepare()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
*/
package ch.srgssr.pillarbox.player.monitoring

import android.content.Context
import android.os.Looper
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.test.utils.FakeClock
import androidx.media3.test.utils.robolectric.TestPlayerRunHelper
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.srgssr.pillarbox.player.PillarboxExoPlayer
import ch.srgssr.pillarbox.player.monitoring.models.Message
Expand All @@ -36,16 +33,15 @@ class MonitoringTest {
private lateinit var player: PillarboxExoPlayer
private lateinit var monitoringMessageHandler: MonitoringMessageHandler

@BeforeTest
@OptIn(ExperimentalCoroutinesApi::class)
@BeforeTest
fun setUp() {
val context = ApplicationProvider.getApplicationContext<Context>()
monitoringMessageHandler = mockk(relaxed = true)
player = PillarboxExoPlayer(context) {
clock(FakeClock(true))
coroutineContext(UnconfinedTestDispatcher())
player = PillarboxExoPlayer {
monitoring = monitoringMessageHandler
coroutineContext(UnconfinedTestDispatcher())
}

player.prepare()
player.play()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class PlayerSessionStateTest {

@Test
fun `create with Pillarbox player`() {
val context = ApplicationProvider.getApplicationContext<Context>()
val player = PillarboxExoPlayer(context).apply {
val player = PillarboxExoPlayer().apply {
smoothSeekingEnabled = false
trackingEnabled = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import android.content.Context
import android.os.Looper
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.exoplayer.DefaultLoadControl
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import androidx.media3.test.utils.FakeClock
import androidx.media3.test.utils.robolectric.TestPlayerRunHelper
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
Expand All @@ -25,7 +23,6 @@ import io.mockk.verify
import io.mockk.verifyOrder
import org.junit.runner.RunWith
import org.robolectric.Shadows.shadowOf
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
Expand All @@ -41,10 +38,7 @@ class BlockedTimeRangeTrackerTest {
fun createPlayer() {
val context = ApplicationProvider.getApplicationContext<Context>()
listener = spyk(object : PillarboxPlayer.Listener {})
player = PillarboxExoPlayer(context) {
loadControl(DefaultLoadControl())
clock(FakeClock(true))
coroutineContext(EmptyCoroutineContext)
player = PillarboxExoPlayer {
+BlockedAssetLoader(context)
}
player.addListener(listener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import android.content.Context
import android.os.Looper
import androidx.media3.common.MediaMetadata
import androidx.media3.common.Player
import androidx.media3.exoplayer.DefaultLoadControl
import androidx.media3.test.utils.FakeClock
import androidx.media3.test.utils.robolectric.RobolectricUtil
import androidx.media3.test.utils.robolectric.TestPlayerRunHelper
import androidx.test.core.app.ApplicationProvider
Expand All @@ -23,7 +21,6 @@ import io.mockk.verifyAll
import io.mockk.verifyOrder
import org.junit.runner.RunWith
import org.robolectric.Shadows.shadowOf
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
Expand All @@ -39,10 +36,7 @@ class MediaItemTrackerTest {
fun createPlayer() {
val context = ApplicationProvider.getApplicationContext<Context>()
fakeMediaItemTracker = spyk(FakeMediaItemTracker())
player = PillarboxExoPlayer(context) {
loadControl(DefaultLoadControl())
clock(FakeClock(true))
coroutineContext(EmptyCoroutineContext)
player = PillarboxExoPlayer {
+FakeAssetLoader(context, fakeMediaItemTracker)
}
}
Expand Down
Loading

0 comments on commit 0cc373a

Please sign in to comment.