Skip to content

Commit

Permalink
Remove ExoPlayer.Builder from PillarboxPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
StaehliJ committed Nov 2, 2023
1 parent 0dfd225 commit 0092fa4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,20 @@
package ch.srgssr.pillarbox.core.business

import android.content.Context
import androidx.media3.common.TrackSelectionParameters
import androidx.media3.datasource.DataSource
import androidx.media3.exoplayer.DefaultLoadControl
import androidx.media3.exoplayer.DefaultRenderersFactory
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
import androidx.media3.exoplayer.upstream.DefaultBandwidthMeter
import androidx.media3.exoplayer.LoadControl
import ch.srgssr.pillarbox.core.business.akamai.AkamaiTokenDataSource
import ch.srgssr.pillarbox.core.business.integrationlayer.service.DefaultMediaCompositionDataSource
import ch.srgssr.pillarbox.core.business.integrationlayer.service.Vector.getVector
import ch.srgssr.pillarbox.core.business.tracker.DefaultMediaItemTrackerRepository
import ch.srgssr.pillarbox.player.PillarboxPlayer
import ch.srgssr.pillarbox.player.SeekIncrement
import ch.srgssr.pillarbox.player.extension.setPreferredAudioRoleFlagsToAccessibilityManagerSettings
import ch.srgssr.pillarbox.player.extension.setSeekIncrements
import ch.srgssr.pillarbox.player.source.PillarboxMediaSourceFactory
import ch.srgssr.pillarbox.player.data.MediaItemSource
import ch.srgssr.pillarbox.player.tracker.MediaItemTrackerProvider
import kotlin.time.Duration.Companion.seconds

/**
* DefaultPillarbox convenient class to create [PillarboxPlayer] that suit SRG needs.
* DefaultPillarbox convenient class to create [PillarboxPlayer] that suit Default SRG needs.
*/
object DefaultPillarbox {
private val defaultSeekIncrement = SeekIncrement(backward = 10.seconds, forward = 30.seconds)
Expand All @@ -35,67 +28,27 @@ object DefaultPillarbox {
*
* @param context The context.
* @param seekIncrement The seek increment.
* @param mediaItemTrackerRepository The provider of MediaItemTracker.
* @param trackerProvider The [TrackerDataProvider] to customize tracker data.
* @param mediaItemTrackerRepository The provider of MediaItemTracker, by default [DefaultMediaItemTrackerRepository].
* @param mediaItemSource The MediaItem source by default [MediaCompositionMediaItemSource].
* @param dataSourceFactory The Http exoplayer data source factory, by default [AkamaiTokenDataSource.Factory].
* @param loadControl The load control, bye default [DefaultLoadControl].
* @return [PillarboxPlayer] suited for SRG.
*/
operator fun invoke(
context: Context,
seekIncrement: SeekIncrement = defaultSeekIncrement,
mediaItemTrackerRepository: MediaItemTrackerProvider = DefaultMediaItemTrackerRepository(),
trackerProvider: TrackerDataProvider? = null
mediaItemSource: MediaItemSource = MediaCompositionMediaItemSource(DefaultMediaCompositionDataSource()),
dataSourceFactory: DataSource.Factory = AkamaiTokenDataSource.Factory(),
loadControl: LoadControl = DefaultLoadControl(),
): PillarboxPlayer {
return PillarboxPlayer(
Builder(context, seekIncrement, trackerProvider),
mediaItemTrackerProvider = mediaItemTrackerRepository
context = context,
seekIncrement = seekIncrement,
dataSourceFactory = dataSourceFactory,
mediaItemSource = mediaItemSource,
mediaItemTrackerProvider = mediaItemTrackerRepository,
loadControl = loadControl
)
}

/**
* Builder convenient class to create a [ExoPlayer.Builder] that suit SRG needs.
*/
object Builder {
/**
* Invoke
*
* @param context The context.
* @param seekIncrement The seek increment.
* @param trackerProvider The [TrackerDataProvider] to customize tracker data.
* @return [ExoPlayer.Builder] suited for SRG.
*/
operator fun invoke(
context: Context,
seekIncrement: SeekIncrement = defaultSeekIncrement,
trackerProvider: TrackerDataProvider? = null
): ExoPlayer.Builder {
return ExoPlayer.Builder(context)
.setUsePlatformDiagnostics(false)
.setSeekIncrements(seekIncrement)
.setRenderersFactory(
DefaultRenderersFactory(context)
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF)
.setEnableDecoderFallback(true)
)
.setBandwidthMeter(DefaultBandwidthMeter.getSingletonInstance(context))
.setLoadControl(DefaultLoadControl())
.setMediaSourceFactory(
PillarboxMediaSourceFactory(
mediaItemSource = MediaCompositionMediaItemSource(
DefaultMediaCompositionDataSource(vector = context.getVector()),
trackerProvider
),
defaultMediaSourceFactory = DefaultMediaSourceFactory(AkamaiTokenDataSource.Factory())
)
)
.setTrackSelector(
DefaultTrackSelector(
context,
TrackSelectionParameters.Builder(context)
.setPreferredAudioRoleFlagsToAccessibilityManagerSettings(context)
.build()
)
)
.setDeviceVolumeControlEnabled(true) // allow player to control device volume
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
package ch.srgssr.pillarbox.demo.shared.di

import android.content.Context
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import ch.srgssr.pillarbox.core.business.DefaultPillarbox
import ch.srgssr.pillarbox.core.business.MediaCompositionMediaItemSource
import ch.srgssr.pillarbox.core.business.akamai.AkamaiTokenDataSource
import ch.srgssr.pillarbox.core.business.integrationlayer.service.DefaultMediaCompositionDataSource
import ch.srgssr.pillarbox.core.business.integrationlayer.service.Vector.getVector
import ch.srgssr.pillarbox.core.business.tracker.DefaultMediaItemTrackerRepository
import ch.srgssr.pillarbox.demo.shared.data.MixedMediaItemSource
import ch.srgssr.pillarbox.player.PillarboxPlayer
import ch.srgssr.pillarbox.player.source.PillarboxMediaSourceFactory

/**
* Dependencies to make custom Dependency Injection
Expand All @@ -35,13 +31,6 @@ object PlayerModule {
* Provide default player that allow to play urls and urns content from the SRG
*/
fun provideDefaultPlayer(context: Context): PillarboxPlayer {
val builder = DefaultPillarbox.Builder(context)
builder.setMediaSourceFactory(
PillarboxMediaSourceFactory(
mediaItemSource = provideMixedItemSource(context),
defaultMediaSourceFactory = DefaultMediaSourceFactory(AkamaiTokenDataSource.Factory())
)
)
return PillarboxPlayer(builder, DefaultMediaItemTrackerRepository())
return DefaultPillarbox(context = context, mediaItemSource = provideMixedItemSource(context))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ class PillarboxPlayer internal constructor(
}
}

constructor(builder: ExoPlayer.Builder, mediaItemTrackerProvider: MediaItemTrackerProvider? = null) : this(
exoPlayer = builder.build(),
mediaItemTrackerProvider = mediaItemTrackerProvider
)

constructor(
context: Context,
mediaItemSource: MediaItemSource,
Expand Down

0 comments on commit 0092fa4

Please sign in to comment.