Skip to main content

CLAppleTVPlayer

The AVPlayerViewController proxy, which provides playback capabilities using the default system UI.

Example​

import {CLAppleTVPlayer} from '@castlabs/react-native-prestoplay';

Remarks​

Not supported on Android.

Constructors​

new CLAppleTVPlayer()​

new CLAppleTVPlayer(): CLAppleTVPlayer

Properties​

audioTrackChanged​

static audioTrackChanged?: AudioTrackChangedCallback;

Triggered on audio track changed.


didPlayToEnd​

static didPlayToEnd?: GenericEventCallback;

Triggered on playback ended. Close the player or change the stream here.


didSeek​

static didSeek?: DidSeekCallback;

Triggered on seeking completed.


onError​

static onError?: ErrorEventCallback;

Triggered on error thrown.


playerIsClosed​

static playerIsClosed?: GenericEventCallback;

Triggered on player closed.


skipToNextChannel​

static skipToNextChannel?: GenericEventCallback;

Triggered when the user skips to the next channel.

This callback is only triggered for live streams and when a single stream is loaded. It is not triggered when a playlist is in use, i.e., when multiple streams are queued. To replace the current stream with the next one, call the CLAppleTVPlayer.openPlayer method.


skipToPreviousChannel​

static skipToPreviousChannel?: GenericEventCallback;

Triggered when the user skips to the previous channel.

This callback is only triggered for live streams and when a single stream is loaded. It is not triggered when a playlist is in use, i.e., when multiple streams are queued. To replace the current stream with the next one, call the CLAppleTVPlayer.openPlayer method.


streamChanged​

static streamChanged?: StreamChangedCallback;

Triggered on stream changed.


subtitleTrackChanged​

static subtitleTrackChanged?: SubtitleTrackChangedCallback;

Triggered on subtitle track changed.


timeControlStatus​

static timeControlStatus?: GenericEventCallback;

Triggered on playback status changed.


willSeek​

static willSeek?: WillSeekCallback;

Triggered on seeking started.

Methods​

addActionListener()​

static addActionListener(listener): EmitterSubscription

Subscribes to the action event.

Parameters​

ParameterTypeDescription
listener(event) => voidthe listener

Returns​

the event subscription

Example​

CLAppleTVPlayer.addActionListener((event: any) => {
switch (event.id) {
case ActionId.Speed:
CLAppleTVPlayer.setRate(Number(event.data));
break;
case ActionId.Skip00:
CLAppleTVPlayer.seekToSecond(15);
break;
}
});

closePlayer()​

static closePlayer(): void

Closes the player.


getAudioTrack()​

static getAudioTrack(): Promise<AudioTrack>

Returns the current audio track.

Returns​

the current audio track


getCurrentStreamIndex()​

static getCurrentStreamIndex(): Promise<number>

Returns the index of the current stream.

Returns​

the current stream index


getLiveStartTime()​

static getLiveStartTime(): Promise<number>

Returns the live start time. A live HLS stream has to have the EXT-X-PROGRAM-DATE-TIME defined.

Returns​

The live start time since the epoch in seconds; -1 if it is unknown or not applicable.


getPosition()​

static getPosition(): Promise<number>

Returns the current playhead.

Returns​

the current position in seconds


getSubtitleTrack()​

static getSubtitleTrack(): Promise<SubtitleTrack>

Returns the current subtitle track.

Returns​

the current subtitle track


openPlayer()​

static openPlayer(
streams,
options?,
transportBarActions?,
infoTabActions?,
contextualActions?,
loopStreams?,
onError?,
onSuccess?): void

Opens the player.

If a single stream is loaded, the CLAppleTVPlayer.skipToNextChannel and CLAppleTVPlayer.skipToPreviousChannel callbacks are fired when the user skips to the next or previous channel. Also, when a single stream is loaded, you can replace it with another by calling the CLAppleTVPlayer.openPlayer method again. This is particularly useful if you want to replace the current stream with a different one.

If multiple streams are loaded, the player will automatically switch to the next stream when the current stream ends. In addition, the CLAppleTVPlayer.streamChanged callback will be fired when the player switches to the next stream. When all streams are live, the user can use the TV remote to switch between channels. However, the CLAppleTVPlayer.skipToNextChannel and CLAppleTVPlayer.skipToPreviousChannel callbacks will not fire.

If loopStream is false, the player will ignore next or previous channel requests if the current stream is the last or first item in the list. The player will still display the channel's interstitial view, but will not change the stream.

Parameters​

ParameterTypeDescription
streamsTVStream[]the stream configuration
options?PlayerOptionsthe player options
transportBarActions?(Action | PopupMenu)[]the transport bar actions
infoTabActions?Action[]the info tab actions
contextualActions?Action[]the contextual actions
loopStreams?Booleanloops through the streams list. Default is true.
onError?(error) => voidthe error callback
onSuccess?() => voidthe success callback

pause()​

static pause(): void

Pauses playback.


play()​

static play(): void

Starts playback.


removeActionListener()​

static removeActionListener(subscription): void

Unsubscribes from the action event.

Parameters​

ParameterTypeDescription
subscriptionEmitterSubscriptionthe event subscription

seekToSecond()​

static seekToSecond(second): void

Moves playhead to the given position.

Parameters​

ParameterTypeDescription
secondnumberthe new position in seconds

setActionStateAndUi()​

static setActionStateAndUi(
id,
state,
uiProp): void

Changes the state of the action and UI appearance.

Parameters​

ParameterTypeDescription
idstringthe action identifier
statebooleanthe action state
uiPropActionUiPropertythe action title and image resource name in Xcode project

setContextualActions()​

static setContextualActions(contextualActions): void

Sets contextual actions.

Parameters​

ParameterTypeDescription
contextualActionsAction[]the contextual actions

setInfoTabActions()​

static setInfoTabActions(infoTabActions): void

Sets info tab actions.

Parameters​

ParameterTypeDescription
infoTabActionsAction[]the info tab actions

setMetadata()​

static setMetadata(metadata): void

Sets the metadata to be displayed in the title view and info tab.

Parameters​

ParameterTypeDescription
metadataChannelMetadatathe channel metadata

setOptions()​

static setOptions(options): void

Sets player options.

Parameters​

ParameterTypeDescription
optionsPlayerOptionsthe player options

setRate()​

static setRate(rate): void

Sets the new playback rate.

Parameters​

ParameterTypeDescription
ratenumberthe playback rate

setTransportBarActions()​

static setTransportBarActions(transportBarActions): void

Sets transport bar actions.

Parameters​

ParameterTypeDescription
transportBarActions(Action | PopupMenu)[]the transport bar actions