-
Notifications
You must be signed in to change notification settings - Fork 5
891 add dsl for pillarboxcastplayer #894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ebe0714
First draft
StaehliJ ba9d19d
Update with dsl
StaehliJ a8e055a
Add dsl for the SRG
StaehliJ efc0cd5
Don't create listener if not needed
StaehliJ 747029a
Update README
StaehliJ 5752ebe
Fix typo
StaehliJ 1615440
Update doc with new dsl api
StaehliJ 94c5524
Small documentation updates
MGaetan89 fdabbad
Update pillarbox-core-business-cast/docs/README.md
StaehliJ f814bf9
Remove not necessary default values
StaehliJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
pillarbox-cast/src/main/java/ch/srgssr/pillarbox/cast/PillarboxCastPlayerBuilder.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| /* | ||
| * Copyright (c) SRG SSR. All rights reserved. | ||
| * License information is available from the LICENSE file. | ||
| */ | ||
| package ch.srgssr.pillarbox.cast | ||
|
|
||
| import android.content.Context | ||
| import androidx.media3.cast.DefaultMediaItemConverter | ||
| import androidx.media3.cast.MediaItemConverter | ||
| import androidx.media3.cast.SessionAvailabilityListener | ||
| import androidx.media3.common.C | ||
| import androidx.media3.common.MediaItem | ||
| import ch.srgssr.pillarbox.player.PillarboxDsl | ||
| import kotlin.time.Duration | ||
| import kotlin.time.Duration.Companion.milliseconds | ||
|
|
||
| /** | ||
| * A builder class for creating instances of [PillarboxCastPlayer]. | ||
| * | ||
| * This builder provides a fluent API for configuring various aspects of the player, such as seek increments, item converters, ... | ||
| */ | ||
| @PillarboxDsl | ||
| abstract class PillarboxCastPlayerBuilder { | ||
| private var mediaItemConverter: MediaItemConverter = DefaultMediaItemConverter() | ||
| private var seekBackIncrement: Duration = C.DEFAULT_SEEK_BACK_INCREMENT_MS.milliseconds | ||
| private var seekForwardIncrement: Duration = C.DEFAULT_SEEK_FORWARD_INCREMENT_MS.milliseconds | ||
| private var maxSeekToPreviousPosition: Duration = C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS.milliseconds | ||
| private var trackSelector: CastTrackSelector = DefaultCastTrackSelector | ||
| private var onCastSessionAvailable: (PillarboxCastPlayer.() -> Unit)? = null | ||
| private var onCastSessionUnavailable: (PillarboxCastPlayer.() -> Unit)? = null | ||
|
|
||
| /** | ||
| * @param seekBackIncrement The [PillarboxCastPlayer.seekBack] increment. | ||
| */ | ||
| fun seekBackIncrement(seekBackIncrement: Duration) { | ||
| check(seekBackIncrement > Duration.ZERO) | ||
| this.seekBackIncrement = seekBackIncrement | ||
| } | ||
|
|
||
| /** | ||
| * @param seekForwardIncrement The [PillarboxCastPlayer.seekForward] increment. | ||
| */ | ||
| fun seekForwardIncrement(seekForwardIncrement: Duration) { | ||
| check(seekForwardIncrement > Duration.ZERO) | ||
| this.seekForwardIncrement = seekForwardIncrement | ||
| } | ||
|
|
||
| /** | ||
| * @param maxSeekToPreviousPosition The maximum position for which [PillarboxCastPlayer.seekToPrevious] seeks to the previous [MediaItem]. | ||
| */ | ||
| fun maxSeekToPreviousPosition(maxSeekToPreviousPosition: Duration) { | ||
| check(maxSeekToPreviousPosition >= Duration.ZERO) | ||
| this.maxSeekToPreviousPosition = maxSeekToPreviousPosition | ||
| } | ||
|
|
||
| /** | ||
| * Track selector | ||
| * | ||
| * @param trackSelector The [CastTrackSelector] to use. | ||
| */ | ||
| fun trackSelector(trackSelector: CastTrackSelector) { | ||
| this.trackSelector = trackSelector | ||
| } | ||
|
|
||
| /** | ||
| * On cast session available | ||
| * | ||
| * @param onCastSessionAvailable The method to invoke when [SessionAvailabilityListener.onCastSessionAvailable] is called. | ||
| */ | ||
| fun onCastSessionAvailable(onCastSessionAvailable: PillarboxCastPlayer.() -> Unit) { | ||
| this.onCastSessionAvailable = onCastSessionAvailable | ||
| } | ||
|
|
||
| /** | ||
| * On cast session unavailable | ||
| * | ||
| * @param onCastSessionUnavailable The method to invoke when [SessionAvailabilityListener.onCastSessionUnavailable] is called. | ||
| */ | ||
| fun onCastSessionUnavailable(onCastSessionUnavailable: PillarboxCastPlayer.() -> Unit) { | ||
| this.onCastSessionUnavailable = onCastSessionUnavailable | ||
| } | ||
|
|
||
| /** | ||
| * Media item converter | ||
| * | ||
| * @param mediaItemConverter The [MediaItemConverter] to use. | ||
| */ | ||
| fun mediaItemConverter(mediaItemConverter: MediaItemConverter) { | ||
| this.mediaItemConverter = mediaItemConverter | ||
| } | ||
|
|
||
| internal fun create(context: Context): PillarboxCastPlayer { | ||
| return PillarboxCastPlayer( | ||
| context.getCastContext(), | ||
| context, | ||
| mediaItemConverter, | ||
| seekBackIncrement.inWholeMilliseconds, | ||
| seekForwardIncrement.inWholeMilliseconds, | ||
| maxSeekToPreviousPosition.inWholeMilliseconds, | ||
| trackSelector, | ||
| ).apply { | ||
| if (onCastSessionAvailable == null && onCastSessionUnavailable == null) return@apply | ||
| setSessionAvailabilityListener(object : SessionAvailabilityListener { | ||
| override fun onCastSessionAvailable() { | ||
| onCastSessionAvailable?.invoke(this@apply) | ||
| } | ||
|
|
||
| override fun onCastSessionUnavailable() { | ||
| onCastSessionUnavailable?.invoke(this@apply) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Defines a factory for creating instances of [PillarboxCastPlayerBuilder]. | ||
| * | ||
| * @param Builder The type of [PillarboxCastPlayerBuilder] that this factory creates. | ||
| */ | ||
| interface CastPlayerConfig<Builder : PillarboxCastPlayerBuilder> { | ||
| /** | ||
| * Creates a new instance of the [Builder] class. | ||
| * | ||
| * @return A new instance of the [Builder]. | ||
| */ | ||
| fun create(): Builder | ||
| } | ||
|
|
||
| /** | ||
| * Default configuration for creating a [PillarboxCastPlayer]. | ||
| */ | ||
| object Default : CastPlayerConfig<Default.Builder> { | ||
| override fun create(): Builder { | ||
| return Builder | ||
| } | ||
|
|
||
| /** | ||
| * A builder class for creating and configuring a [PillarboxCastPlayer]. | ||
| */ | ||
| object Builder : PillarboxCastPlayerBuilder() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.