Package com.castlabs.android.player
Class SingleControllerPlaylist
- java.lang.Object
-
- com.castlabs.android.player.PlayerController
-
- com.castlabs.android.player.SingleControllerPlaylist
-
- All Implemented Interfaces:
Playlist
public class SingleControllerPlaylist extends PlayerController implements Playlist
Playlist
implementation. As the Class name suggests, this Playlist implementation relies in the usage of a singlePlayerController
, which is theSingleControllerPlaylist
itself. This implementation allows for multiplePlayerConfigs
to be loaded and played in sequential order. You can start playback with one of the open methods. Several Playlist manipulation operations are available, such asaddItem(PlayerConfig)
,swap(PlayerConfig, PlayerConfig)
, orremoveItem(PlayerConfig)
. You should also register aSingleControllerPlaylist.PlaylistListener
in the constructor to get Playlist-specific events, such as when a Playlist item change occurs. The current Playlist can be obtained withgetPlaylist()
and the current item withgetCurrentItem()
. The SingleControllerPlaylist operates onPlayerConfig
objects. In order to use theSingleControllerPlaylist
you should explicitly create it through itsconstructor
. And, if you're using aPlayerView
, set it with thePlayerView.setPlayerController(PlayerController)
in yourActivity
.onCreate(Bundle) method. The playlist supports mixed clear-protected items where all protected items have the sameDrm
type. Note that initial DRM configuration shall be setsetInitialDrmConfiguration(DrmConfiguration)
when using dynamic playlist with mixed items and starting playlist with clear item followed by at least one protected.- Since:
- 4.2.5
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SingleControllerPlaylist.PlaylistListener
Playlist-related events listener.-
Nested classes/interfaces inherited from class com.castlabs.android.player.PlayerController
PlayerController.State, PlayerController.TrackType
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_PLAYLIST_MAX_LOADED_ITEMS
The default maximum number overall of Playlist items to keep loaded at any time.static int
DEFAULT_PLAYLIST_WINDOW_AFTER
The default number of Playlist items to load after the current one.static int
DEFAULT_PLAYLIST_WINDOW_BEFORE
The default number of Playlist items to load before the current one.-
Fields inherited from class com.castlabs.android.player.PlayerController
AUDIO_RENDERER, DTS_RENDERER, METADATA_RENDERER, TEXT_RENDERER, UNKNOWN_RENDERER, VIDEO_RENDERER
-
-
Constructor Summary
Constructors Constructor Description SingleControllerPlaylist(Context context, SingleControllerPlaylist.PlaylistListener playlistListener)
Create a new player controller using the given context
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addItem(int position, PlayerConfig config)
Adds an item at the specified position in the playlist.void
addItem(PlayerConfig config)
Adds an item at the end of the playlist.void
addPlaylistListener(SingleControllerPlaylist.PlaylistListener playlistListener)
com.google.android.exoplayer2.source.MediaSource
createContentMediaSource(PlayerConfig playerConfig, PlayerPlugin playerPlugin)
Creates a MediaSource for just one PlayerConfig.PlayerConfig
getCurrentItem()
Returns the currently playing itemint
getCurrentItemIndex()
Returns current item indexint
getMaximumLoadedItems()
int
getNextItemIndex()
List<PlayerConfig>
getPlaylist()
Returns the current Playlist as a List ofPlayerConfig
items.int
getPlaylistWindowAfter()
int
getPlaylistWindowBefore()
int
getPreviousItemIndex()
int
getSize()
Returns the number of Configs in the playlist.PlayerConfig
nextItem()
Advances playback to the next Playlist item.void
open(int startIndex, Parcelable... playerConfigs)
Start playback with the specified index and with an Array ofPlayerConfigs
orBundles
.void
open(int startIndex, List<? extends Parcelable> playerConfigs)
Start playback with the specified index and player configsvoid
open(Bundle bundle)
This method takes aBundle
and extracts the information to create aPlayerConfig
from the bundle.void
open(Parcelable... playerConfigs)
Starts playback with an Array ofPlayerConfigs
orBundles
.void
open(PlayerConfig playerConfig)
Opens the given URL to the video.void
open(List<? extends Parcelable> playerConfigs)
Starts playback with a List ofPlayerConfigs
orBundles
.void
openState(Bundle bundle)
Opens the {link PlayerController} with the givenBundle
which is the saved state obtained withPlayerController.saveState(Bundle)
PlayerConfig
playItem(int index)
Advances playback to the Playlist item specified by the index.PlayerConfig
playItem(int index, long positionInPeriodUs)
Plays the item at the specified indexPlayerConfig
previousItem()
Moves backwards in the Playlist.PlayerConfig
previousItem(long positionMs)
Moves backwards in the Playlist.void
removeItem(PlayerConfig config)
Removes an item from the Playlistvoid
removePlaylistListener(SingleControllerPlaylist.PlaylistListener playlistListener)
boolean
saveState(Bundle targetBundle)
Saves the state of this controller to the given target bundle.void
seekWith(long offsetUs)
Sets the player to the new position by applying the offset to the current position i.e.void
setInitialDrmConfiguration(DrmConfiguration drmConfiguration)
InitialDrmConfiguration
used to initialize and configure DRM session manager when playback is started with clear playlist item.void
setMaximumLoadedItems(int maximumLoadedItems)
Set the maximum number overall of Playlist items to keep loaded at any time.void
setPlaylistWindowAfter(int playlistWindowAfter)
Sets the number of Playlist items to load after the current one.void
setPlaylistWindowBefore(int playlistWindowBefore)
Sets the number of Playlist items to load before the current one.void
setWrapAroundPlaylistEdges(boolean wrapPlaylist)
Set whether the Playlist should wrap around the edges.void
swap(PlayerConfig playerConfig1, PlayerConfig playerConfig2)
Interchanges two Playlist items.-
Methods inherited from class com.castlabs.android.player.PlayerController
addAudioRendererListener, addCatchupListener, addCustomDashEventListener, addDrmEventListener, addFormatChangeListener, addHttpListener, addMetadataListener, addPeriodChangedListener, addPlayerControllerListener, addPlayerListener, addPlayerModelFilter, addRequestModifier, addResponseModifier, addStreamingEventListener, addSubtitleTrack, addThumbnailTrack, addTimelineChangedListener, addTimelineListener, addTrackSelectionListener, addVideoRendererListener, destroy, disableAudioFocus, enableTrickplayMode, getAbrConfiguration, getAdClientInterface, getAdInterface, getAnalyticsMetaData, getAnalyticsSession, getAudioAttributes, getAudioFocusCallback, getAudioTrack, getAudioTracks, getBackBufferTime, getBandwidthMeterWrapper, getBitrateEstimate, getBufferConfiguration, getBufferedPercentage, getBufferedPosition, getBufferSizeBytes, getBufferSizeTime, getComponent, getComponentView, getContext, getDataSourceFactory, getDuration, getHlsKeyCache, getKeyStore, getLicenseRemainingDurationSec, getLicenseRemainingDurationSec, getLiveConfiguration, getLiveEdgeLatency, getLiveEdgeUs, getLiveEdgeUs, getLiveStartTime, getMainHandler, getMaxBufferSizeBytes, getMediaCodecSelector, getNetworkConfiguration, getOfflinePath, getPath, getPlayer, getPlayerConfig, getPlayerListeners, getPlayerState, getPlayerView, getPosition, getPositionInPeriod, getPreBufferTime, getRequestModifiers, getResponseModifiers, getSecondaryDisplay, getSeekRangeEndUs, getSpeed, getSSLSocketFactory, getSubtitlesStyle, getSubtitleTrack, getSubtitleTracks, getThumbnailTracks, getTimeline, getTrickplayConfiguration, getVideoFilterConfiguration, getVideoQualities, getVideoQuality, getVideoQualityMode, getVideoSizeFilter, getVideoTrack, getVideoTracks, getVolume, getWindowPositionInFirstPeriod, isBackgrounded, isCatchingUp, isHdPlaybackEnabled, isLive, isLoopingEnabled, isPlaying, isPlayWhenReady, isSeeking, isSupportedAudioCodec, isTrickplayMode, movePlayerListeners, pause, play, queryKeyStatus, queryKeyStatus, registerDrmSession, release, releaseWithException, removeAudioRendererListener, removeCatchupListener, removeDrmEventListener, removeFormatChangeListener, removeHttpListener, removeMetadataListener, removePeriodChangedListener, removePlayerControllerListener, removePlayerListener, removePlayerModelFilter, removeRequestModifier, removeResponseModifier, removeStreamingEventListener, removeTimelineChangedListener, removeTimelineListener, removeTrackSelectionListener, removeVideoRendererListener, resetAudioFocus, scanComponentViews, setAbrConfiguration, setAnalyticsMetaData, setAnalyticsSession, setAudioFocusCallback, setAudioTrack, setBackgrounded, setBufferConfiguration, setComponentView, setConfigurationProvider, setDataSourceFactory, setDisableAnalytics, setExternalSourceSelector, setHdPlaybackEnabled, setHlsKeyCache, setInitialPositionProvider, setInternalSourceSelectorFactory, setLiveConfiguration, setLoopingEnabled, setMaxVideoSizeFilter, setPeriodInfoProvider, setPlayerView, setPosition, setPosition, setPositionInPeriod, setSecondaryDisplay, setSourceSelector, setSpeed, setSSLSocketFactory, setSubtitlesStyle, setSubtitleTrack, setSurface, setTrickplayConfiguration, setVideoFilterConfiguration, setVideoQuality, setVideoTrack, setVideoTrack, setVolume, unsetComponentView, unsetComponentViews, waitForMessages
-
-
-
-
Field Detail
-
DEFAULT_PLAYLIST_WINDOW_BEFORE
public static final int DEFAULT_PLAYLIST_WINDOW_BEFORE
The default number of Playlist items to load before the current one.- See Also:
- Constant Field Values
-
DEFAULT_PLAYLIST_WINDOW_AFTER
public static final int DEFAULT_PLAYLIST_WINDOW_AFTER
The default number of Playlist items to load after the current one.- See Also:
- Constant Field Values
-
DEFAULT_PLAYLIST_MAX_LOADED_ITEMS
public static final int DEFAULT_PLAYLIST_MAX_LOADED_ITEMS
The default maximum number overall of Playlist items to keep loaded at any time.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SingleControllerPlaylist
public SingleControllerPlaylist(@NonNull Context context, @Nullable SingleControllerPlaylist.PlaylistListener playlistListener)
Create a new player controller using the given context- Parameters:
context
- the contextplaylistListener
- optionalSingleControllerPlaylist.PlaylistListener
to be informed about playlist-specific events
-
-
Method Detail
-
addPlaylistListener
public void addPlaylistListener(@NonNull SingleControllerPlaylist.PlaylistListener playlistListener)
-
removePlaylistListener
public void removePlaylistListener(@NonNull SingleControllerPlaylist.PlaylistListener playlistListener)
-
setInitialDrmConfiguration
public void setInitialDrmConfiguration(@Nullable DrmConfiguration drmConfiguration)
InitialDrmConfiguration
used to initialize and configure DRM session manager when playback is started with clear playlist item. Initial DRM configuration is only needed to be set when adding items dynamically into the playlist and the very first item is in clear. Note that when protected item is started playing then the correspondingDrmConfiguration
is used which is part of item'sPlayerConfig
- Parameters:
drmConfiguration
- InitialDrmConfiguration
-
getPlaylistWindowBefore
public int getPlaylistWindowBefore()
- Returns:
- the number of Playlist items to load before the current one.
-
setPlaylistWindowBefore
public void setPlaylistWindowBefore(int playlistWindowBefore)
Sets the number of Playlist items to load before the current one.- Parameters:
playlistWindowBefore
- the number of items before
-
getPlaylistWindowAfter
public int getPlaylistWindowAfter()
- Returns:
- the number of Playlist items to load after the current one.
-
setPlaylistWindowAfter
public void setPlaylistWindowAfter(int playlistWindowAfter)
Sets the number of Playlist items to load after the current one.- Parameters:
playlistWindowAfter
- the number of items after
-
getMaximumLoadedItems
public int getMaximumLoadedItems()
- Returns:
- the maximum number overall of Playlist items to keep loaded at any time.
-
setMaximumLoadedItems
public void setMaximumLoadedItems(int maximumLoadedItems)
Set the maximum number overall of Playlist items to keep loaded at any time.- Parameters:
maximumLoadedItems
- the number of items
-
createContentMediaSource
@NonNull public com.google.android.exoplayer2.source.MediaSource createContentMediaSource(@NonNull PlayerConfig playerConfig, @NonNull PlayerPlugin playerPlugin)
Description copied from class:PlayerController
Creates a MediaSource for just one PlayerConfig. The resultin MediaSource will be wrapped by aClippingMediaSource
if needed.- Overrides:
createContentMediaSource
in classPlayerController
- Parameters:
playerConfig
- the config from which to create the MediaSourceplayerPlugin
- thePlayerPlugin
that will create the MediaSource- Returns:
- the MediaSource
-
open
public void open(@NonNull Parcelable... playerConfigs)
Description copied from interface:Playlist
Starts playback with an Array ofPlayerConfigs
orBundles
.
-
open
public void open(int startIndex, @NonNull Parcelable... playerConfigs)
Description copied from interface:Playlist
Start playback with the specified index and with an Array ofPlayerConfigs
orBundles
.
-
open
public void open(@NonNull Bundle bundle)
Description copied from class:PlayerController
This method takes aBundle
and extracts the information to create aPlayerConfig
from the bundle. The following bundle keys are queried to create the playback state: The following keys will be checked:SdkConsts.INTENT_URL
expects a String (mandatory)SdkConsts.INTENT_START_PLAYING
expects a Boolean (default: true)SdkConsts.INTENT_POSITION_TO_PLAY
expects a Long (default: 0)SdkConsts.INTENT_DRM_CONFIGURATION
expects aDrmConfiguration
(default: null)SdkConsts.INTENT_AUDIO_TRACK_GROUP_IDX
expects aInteger
(default: 0 to play the first track)SdkConsts.INTENT_SUBTITLE_TRACK_GROUP_IDX
expects aInteger
(default: -1 to disable subtitles)SdkConsts.INTENT_CONTENT_TYPE
expects aInteger
(default:SdkConsts.CONTENT_TYPE_UNKNOWN
to auto-detect). Allowed values are one ofSdkConsts.CONTENT_TYPE_UNKNOWN
,SdkConsts.CONTENT_TYPE_DASH
,SdkConsts.CONTENT_TYPE_HLS
,SdkConsts.CONTENT_TYPE_SMOOTHSTREAMING
, orSdkConsts.CONTENT_TYPE_MP4
SdkConsts.INTENT_AUDIO_VOLUME
expects aFloat
with a value 0 <= value <= 1SdkConsts.INTENT_SECONDARY_DISPLAY
expects aInteger
and defaults to the value ofPlayerController.getSecondaryDisplay()
SdkConsts.INTENT_HD_CONTENT_FILTER
expects aInteger
and defaults to the value ofPlayerSDK.PLAYBACK_HD_CONTENT
SdkConsts.INTENT_VIDEO_SIZE_FILTER
expects aPoint
and defaults to the value ofPlayerSDK.VIDEO_SIZE_FILTER
SdkConsts.INTENT_VIDEO_CODEC_FILTER
expects aInteger
and defaults to the value ofPlayerSDK.VIDEO_CODEC_FILTER
SdkConsts.INTENT_ENABLE_LOOPING
expects aBoolean
and if true, enables loopingSdkConsts.INTENT_ANALYTICS_DATA
expects aAnalyticsMetaData
object and is required if you are using one of the analytics pluginsSdkConsts.INTENT_BUFFER_CONFIGURATION
expects aBufferConfiguration
object and can be used to teak the player bufferSdkConsts.INTENT_ABR_CONFIGURATION
expects aAbrConfiguration
object and can be used to teak the players ABR behaviourSdkConsts.INTENT_USER_ID
expects aString
SdkConsts.INTENT_LIVE_CONFIGURATION
expects aLiveConfiguration
object and is used to tweak live-related params
SdkConsts.INTENT_QUERY_PARAMS_BUNDLE
andSdkConsts.INTENT_HEADER_PARAMS_BUNDLE
to configure and add query and header parameters that will be send with each request. This can for example be used to add tokens when remote resources are requested. In both cases, the bundle needs to reference anotherBundle
instance that is then used as a key/value store for the query or header parameters. You can also useSdkConsts.INTENT_SUBTITLE_BUNDLE_ARRAYLIST
to side-load additional subtitle tracks through the bundle. Use the key to store anArrayList
ofBundle
instances that specify side loaded tracks. Useintent.putParcelableArrayListExtra(SdkConsts.INTENT_SUBTITLE_BUNDLE_ARRAYLIST, ...);
to add the list of bundles with the subtitle track information. A full example of this looks like:ArrayList<Bunde> subtitles = new ArrayList<>(); Bundle bundle = new Bundle(); bundle.putString(SdkConsts.INTENT_SUBTITLE_URL, "https://my.com/subtitle.ttml"); bundle.putString(SdkConsts.INTENT_SUBTITLE_MIME_TYPE, SdkConsts.MIME_TYPE_TTML); bundle.putString(SdkConsts.INTENT_SUBTITLE_LANGUAGE, "en"); bundle.putString(SdkConsts.INTENT_SUBTITLE_NAME, "Side-loaded"); subtitles.add(bundle); intent.putExtra(SdkConsts.INTENT_SUBTITLE_BUNDLE_ARRAYLIST, subtitles);
- Overrides:
open
in classPlayerController
- Parameters:
bundle
- the bundle- See Also:
PlayerConfig.Builder.fromBundle(Bundle)
-
open
public void open(@Nullable PlayerConfig playerConfig)
Description copied from class:PlayerController
Opens the given URL to the video. You can specify a path to a local file here, but in this case, please note that the path *needs* to be absolute. The path is treated as a URL and a protocol is expected. If no protocol is specified, the `file://` protocol is assumed and prepended to the given path. If you are using an Analytics Plugin, make sure you usePlayerController.setAnalyticsMetaData(AnalyticsMetaData)
to set the required meta-data before calling this method.- Overrides:
open
in classPlayerController
- Parameters:
playerConfig
- the desired Player configuration
-
addItem
public void addItem(@NonNull PlayerConfig config)
Description copied from interface:Playlist
Adds an item at the end of the playlist.
-
addItem
public void addItem(int position, @NonNull PlayerConfig config)
Description copied from interface:Playlist
Adds an item at the specified position in the playlist.
-
removeItem
public void removeItem(@NonNull PlayerConfig config)
Description copied from interface:Playlist
Removes an item from the Playlist- Specified by:
removeItem
in interfacePlaylist
- Parameters:
config
- item to remove
-
swap
public void swap(@NonNull PlayerConfig playerConfig1, @NonNull PlayerConfig playerConfig2)
Description copied from interface:Playlist
Interchanges two Playlist items. If any of such items is the currently playing item, playback won't be affected.
-
getCurrentItem
@Nullable public PlayerConfig getCurrentItem()
Description copied from interface:Playlist
Returns the currently playing item- Specified by:
getCurrentItem
in interfacePlaylist
- Returns:
- the currently playing item
-
getCurrentItemIndex
public int getCurrentItemIndex()
Description copied from interface:Playlist
Returns current item index- Specified by:
getCurrentItemIndex
in interfacePlaylist
- Returns:
- Current item index or
-1
otherwise
-
getPlaylist
public List<PlayerConfig> getPlaylist()
Description copied from interface:Playlist
Returns the current Playlist as a List ofPlayerConfig
items.- Specified by:
getPlaylist
in interfacePlaylist
- Returns:
- the current Playlist
-
open
public void open(@NonNull List<? extends Parcelable> playerConfigs)
Description copied from interface:Playlist
Starts playback with a List ofPlayerConfigs
orBundles
.
-
open
public void open(int startIndex, @NonNull List<? extends Parcelable> playerConfigs)
Description copied from interface:Playlist
Start playback with the specified index and player configs
-
openState
public void openState(@NonNull Bundle bundle)
Description copied from class:PlayerController
Opens the {link PlayerController} with the givenBundle
which is the saved state obtained withPlayerController.saveState(Bundle)
- Overrides:
openState
in classPlayerController
- Parameters:
bundle
- TheBundle
to open thePlayerController
with
-
saveState
public boolean saveState(@NonNull Bundle targetBundle)
Description copied from class:PlayerController
Saves the state of this controller to the given target bundle. This will store the playback state and all intent parameters that are required to restore the state of this controller usingPlayerController.open(Bundle)
with the target bundle. The only exception is the current video quality selection. The video quality will be stored as the initial quality in the bundle if adaptive bitrate switching is turned off and the quality was selected manually. In that case, adaptive bitrate switching will be turned off when the bundle is used to re-open content.- Overrides:
saveState
in classPlayerController
- Parameters:
targetBundle
- the target bundle- Returns:
- True if the state was saved successfully
-
setWrapAroundPlaylistEdges
public void setWrapAroundPlaylistEdges(boolean wrapPlaylist)
Set whether the Playlist should wrap around the edges. If it is set to true, andnextItem()
is called while playing the last item, the Playlist will transition to the first playlist item. Conversely, ifpreviousItem()
is called while playing the first item, the Playlist will transition to the last playlist item.- Parameters:
wrapPlaylist
- whether to enable playlist wrapping.
-
nextItem
@Nullable public PlayerConfig nextItem()
Description copied from interface:Playlist
Advances playback to the next Playlist item.
-
playItem
@Nullable public PlayerConfig playItem(int index, long positionInPeriodUs)
Plays the item at the specified index- Parameters:
index
- the index of the item to playpositionInPeriodUs
- position within the item to which to seek to- Returns:
- The
PlayerConfig
to Play, or null
-
playItem
@Nullable public PlayerConfig playItem(int index)
Description copied from interface:Playlist
Advances playback to the Playlist item specified by the index.
-
getPreviousItemIndex
public int getPreviousItemIndex()
- Returns:
- Index or
C.INDEX_UNSET
-
getNextItemIndex
public int getNextItemIndex()
- Returns:
- Index or
C.INDEX_UNSET
-
previousItem
@Nullable public PlayerConfig previousItem()
Description copied from interface:Playlist
Moves backwards in the Playlist.- Specified by:
previousItem
in interfacePlaylist
- Returns:
- the next item to play. If null, the start of the Playlist has been reached.
-
previousItem
@Nullable public PlayerConfig previousItem(long positionMs)
Moves backwards in the Playlist.- Parameters:
positionMs
- at which position to playing the item.C.TIME_UNSET
will use the default position andC.TIME_END_OF_SOURCE
will start playing at the end of the item. This last value makes sense if playing backwards.- Returns:
- the next item to play. If null, the start of the Playlist has been reached.
-
seekWith
public void seekWith(long offsetUs)
Sets the player to the new position by applying the offset to the current position i.e. with the negative offset the playback goes backward and with the positive one goes forward. If necessary the playback may go to the previous or next item in the playlist with the calculated playback offset as following: previous item position is previous_item_duration + (current_item_position + offset) and next item position is current_item_position + offset - current_item_duration. In case of seeking within the first or the last item in the playlist then the playback position is clipped to either zero or last item duration correspondingly.- Overrides:
seekWith
in classPlayerController
- Parameters:
offsetUs
- The offset to be applied to the current position
-
-