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 on the next channel skipped in a live stream. Call replaceStream() or replaceStreamAndActions() with the next TVStream value.


skipToPreviousChannel

static skipToPreviousChannel?: GenericEventCallback;

Triggered on the previous channel skipped in a live stream. Call replaceStream() or replaceStreamAndActions() with the previous TVStream value.


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


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(
stream,
options?,
transportBarActions?,
infoTabActions?,
contextualActions?,
onError?,
onSuccess?): void

Opens the player.

Parameters

ParameterTypeDescription
streamTVStreamthe stream configuration
options?PlayerOptionsthe player options
transportBarActions?(Action | PopupMenu)[]the transport bar actions
infoTabActions?Action[]the info tab actions
contextualActions?Action[]the contextual actions
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

replaceStream()

static replaceStream(
stream,
onError?,
onSuccess?): void

Changes the playback stream.

Parameters

ParameterTypeDescription
streamTVStreamthe stream configuration
onError?(error) => voidthe error callback
onSuccess?() => voidthe success callback

replaceStreamAndActions()

static replaceStreamAndActions(
stream,
options?,
transportBarActions?,
infoTabActions?,
contextualActions?,
onError?,
onSuccess?): void

Changes the playback stream, options, and actions.

Parameters

ParameterTypeDescription
streamTVStreamthe stream configuration
options?PlayerOptionsthe player options
transportBarActions?(Action | PopupMenu)[]the transport bar actions
infoTabActions?Action[]the info tab actions
contextualActions?Action[]the contextual actions
onError?(error) => voidthe error callback
onSuccess?() => voidthe success callback

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