bitmovin-player-react-native
Version:
Official React Native bindings for Bitmovin's mobile Player SDKs.
1,687 lines (1,669 loc) • 140 kB
TypeScript
import React$1 from 'react';
import { ViewStyle } from 'react-native';
/**
* Configures the adaptation logic.
*/
interface AdaptationConfig {
/**
* The upper bitrate boundary in bits per second for approximate network bandwidth consumption of the played source.
* Can be set to `undefined` for no limitation.
*/
maxSelectableBitrate?: number;
/**
* The initial bandwidth estimate in bits per second the player uses to select the optimal media tracks before actual bandwidth data is available. Overriding this value should only be done in specific cases and will most of the time not result in better selection logic.
*
* @platform Android
* @see https://cdn.bitmovin.com/player/android/3/docs/player-core/com.bitmovin.player.api.media/-adaptation-config/initial-bandwidth-estimate-override.html
*/
initialBandwidthEstimateOverride?: number;
}
/**
* Quartiles that can be reached during an ad playback.
*/
declare enum AdQuartile {
/**
* Fist ad quartile.
*/
FIRST = "first",
/**
* Mid ad quartile.
*/
MID_POINT = "mid_point",
/**
* Third ad quartile.
*/
THIRD = "third"
}
/**
* The possible types an `AdSource` can be.
*/
declare enum AdSourceType {
/**
* Google Interactive Media Ads.
*/
IMA = "ima",
/**
* Unknown ad source type.
*/
UNKNOWN = "unknown",
/**
* Progressive ad type.
*/
PROGRESSIVE = "progressive"
}
/**
* Represents an ad source which can be assigned to an `AdItem`. An `AdItem` can have multiple `AdSource`s
* as waterfalling option.
*/
interface AdSource {
/**
* The ad tag / url to the ad manifest.
*/
tag: string;
/**
* The `AdSourceType` of this `AdSource`.
*/
type: AdSourceType;
}
/**
* Represents an ad break which can be scheduled for playback.
*
* One single `AdItem` can have multiple `AdSource`s where all but the first act as fallback ad sources
* if the first one fails to load. The start and end of an ad break are signaled via `AdBreakStartedEvent`
* and `AdBreakFinishedEvent`.
*/
interface AdItem {
/**
* The playback position at which the ad break is scheduled to start. Default value is "pre".
*
* Possible values are:
* • "pre": pre-roll ad (for VoD and Live streaming)
* • "post": post-roll ad (for VoD streaming only)
* • fractional seconds: "10", "12.5" (mid-roll ad, for VoD and Live streaming)
* • percentage of the entire video duration: "25%", "50%" (mid-roll ad, for VoD streaming only)
* • timecode hh:mm:ss.mmm: "00:10:30.000", "01:00:00.000" (mid-roll ad, for VoD streaming only)
*/
position?: string;
/**
* The `AdSource`s that make up this `AdItem`. The first ad source in this array is used as the main ad.
* Subsequent ad sources act as a fallback, meaning that if the main ad source does not provide a
* valid response, the subsequent ad sources will be utilized one after another.
*
* The fallback ad sources need to have the same `AdSourceType` as the main ad source.
*/
sources: AdSource[];
/**
* The amount of seconds the ad manifest is loaded in advance
* compared to when the ad break is scheduled for playback.
*
* Default value is 0.0
*
* @platform Android
*/
preloadOffset?: number;
}
/**
* Contains configuration values regarding the ads which should be played back by the player.
*/
interface AdvertisingConfig {
/**
* The ad items that are scheduled when a new playback session is started via `Player.load()`.
*/
schedule: AdItem[];
}
/**
* Contains the base configuration options for an ad.
*/
interface AdConfig {
/**
* Specifies how many seconds of the main video content should be replaced by ad break(s).
*/
replaceContentDuration: number;
}
/**
* Holds various additional ad data.
*/
interface AdData {
/**
* The average bitrate of the progressive media file as defined in the VAST response.
*/
bitrate?: number;
/**
* The maximum bitrate of the streaming media file as defined in the VAST response.
*/
maxBitrate?: number;
/**
* The MIME type of the media file or creative as defined in the VAST response.
*/
mimeType?: string;
/**
* The minimum bitrate of the streaming media file as defined in the VAST response.
*/
minBitrate?: number;
}
/**
* Defines basic properties available for every ad type.
*/
interface Ad {
/**
* The url the user should be redirected to when clicking the ad.
*/
clickThroughUrl?: string;
/**
* Holds various additional `AdData`.
*/
data?: AdData;
/**
* The height of the ad.
*/
height: number;
/**
* Identifier for the ad. This might be autogenerated.
*/
id?: string;
/**
* Determines whether an ad is linear, i.e. playback of main content needs to be paused for the ad.
*/
isLinear: boolean;
/**
* The corresponding media file url for the ad.
*/
mediaFileUrl?: string;
/**
* The width of the ad.
*/
width: number;
}
/**
* Contains information about an ad break.
*/
interface AdBreak {
/**
* The ads scheduled for this `AdBreak`.
*/
ads: Ad[];
/**
* The id of the corresponding `AdBreakConfig`. This will be auto-generated.
*/
id: string;
/**
* The time in seconds in the media timeline the `AdBreak` is scheduled for.
*/
scheduleTime: number;
}
/**
* Object used to configure the build-in analytics collector.
*/
interface AnalyticsConfig {
/**
* The analytics license key
*/
licenseKey: string;
/**
* Flag to enable Ad tracking (default: false).
*/
adTrackingDisabled?: boolean;
/**
* Flag to use randomised userId not depending on device specific values (default: false).
*/
randomizeUserId?: boolean;
/**
* Default metadata to be sent with events.
* Fields of the `SourceMetadata` are prioritized over the default metadata.
*/
defaultMetadata?: DefaultMetadata;
}
/**
* DefaultMetadata that can be used to enrich the analytics data.
* DefaultMetadata is not bound to a specific source and can be used to set fields for the lifecycle of the collector.
* If fields are specified in `SourceMetadata` and `DefaultMetadata`, `SourceMetadata` takes precedence.
*/
interface DefaultMetadata extends CustomDataConfig {
/**
* CDN Provide that the video playback session is using.
*/
cdnProvider?: string;
/**
* User ID of the customer.
*/
customUserId?: string;
}
/**
* `SourceMetadata` that can be used to enrich the analytics data.
*/
interface SourceMetadata extends CustomDataConfig {
/**
* ID of the video in the CMS system
*/
videoId?: String;
/**
* Human readable title of the video asset currently playing
*/
title?: String;
/**
* Breadcrumb path to show where in the app the user is
*/
path?: String;
/**
* Flag to see if stream is live before stream metadata is available
*/
isLive?: boolean;
/**
* CDN Provider that the video playback session is using
*/
cdnProvider?: String;
}
/**
* Free-form data that can be used to enrich the analytics data
* If customData is specified in `SourceMetadata` and `DefaultMetadata`
* data is merged on a field basis with `SourceMetadata` taking precedence.
*/
interface CustomDataConfig {
/**
* Optional free-form custom data
*/
customData1?: string;
/**
* Optional free-form custom data
*/
customData2?: string;
/**
* Optional free-form custom data
*/
customData3?: string;
/**
* Optional free-form custom data
*/
customData4?: string;
/**
* Optional free-form custom data
*/
customData5?: string;
/**
* Optional free-form custom data
*/
customData6?: string;
/**
* Optional free-form custom data
*/
customData7?: string;
/**
* Optional free-form custom data
*/
customData8?: string;
/**
* Optional free-form custom data
*/
customData9?: string;
/**
* Optional free-form custom data
*/
customData10?: string;
/**
* Optional free-form custom data
*/
customData11?: string;
/**
* Optional free-form custom data
*/
customData12?: string;
/**
* Optional free-form custom data
*/
customData13?: string;
/**
* Optional free-form custom data
*/
customData14?: string;
/**
* Optional free-form custom data
*/
customData15?: string;
/**
* Optional free-form custom data
*/
customData16?: string;
/**
* Optional free-form custom data
*/
customData17?: string;
/**
* Optional free-form custom data
*/
customData18?: string;
/**
* Optional free-form custom data
*/
customData19?: string;
/**
* Optional free-form custom data
*/
customData20?: string;
/**
* Optional free-form custom data
*/
customData21?: string;
/**
* Optional free-form custom data
*/
customData22?: string;
/**
* Optional free-form custom data
*/
customData23?: string;
/**
* Optional free-form custom data
*/
customData24?: string;
/**
* Optional free-form custom data
*/
customData25?: string;
/**
* Optional free-form custom data
*/
customData26?: string;
/**
* Optional free-form custom data
*/
customData27?: string;
/**
* Optional free-form custom data
*/
customData28?: string;
/**
* Optional free-form custom data
*/
customData29?: string;
/**
* Optional free-form custom data
*/
customData30?: string;
/**
* Experiment name needed for A/B testing.
*/
experimentName?: string;
}
/**
* Provides the means to control the analytics collected by a `Player`.
* Use the `Player.analytics` property to access a `Player`'s `AnalyticsApi`.
*/
declare class AnalyticsApi {
/**
* The native player id that this analytics api is attached to.
*/
playerId: string;
constructor(playerId: string);
/**
* Sends a sample with the provided custom data.
* Does not change the configured custom data of the collector or source.
*/
sendCustomDataEvent: (customData: CustomDataConfig) => void;
/**
* Gets the current user id used by the bundled analytics instance.
*
* @returns The current user id.
*/
getUserId: () => Promise<string>;
}
/**
* An audio session category defines a set of audio behaviors.
* Choose a category that most accurately describes the audio behavior you require.
*
* Note the `playback` category is required in order to properly enable picture in picture support.
*
* - `ambient`: The category for an app in which sound playback is nonprimary — that is, your app also works with the sound turned off.
* - `multiRoute`: The category for routing distinct streams of audio data to different output devices at the same time.
* - `playAndRecord`: The category for recording (input) and playback (output) of audio, such as for a Voice over Internet Protocol (VoIP) app.
* - `playback`: The category for playing recorded music or other sounds that are central to the successful use of your app.
* - `record`: The category for recording audio while also silencing playback audio.
* - `soloAmbient`: The default audio session category.
*
* @platform iOS
* @see https://developer.apple.com/documentation/avfaudio/avaudiosession/category
*/
type AudioSessionCategory = 'ambient' | 'multiRoute' | 'playAndRecord' | 'playback' | 'record' | 'soloAmbient';
/**
* An object that communicates to the system how you intend to use audio in your app.
*
* @platform iOS
* @see https://developer.apple.com/documentation/avfaudio/avaudiosession
*/
declare const AudioSession: {
/**
* Sets the audio session's category.
*
* @platform iOS
* @see https://developer.apple.com/documentation/avfaudio/avaudiosession/1616583-setcategory
*/
setCategory: (category: AudioSessionCategory) => Promise<void>;
};
/**
* The `MediaTrackRole` interface represents the role of a media track in a media stream.
*/
interface MediaTrackRole {
/**
* The unique identifier for this role instance.
* - On Android: Corresponds to the native [`MediaTrackRole.id`](https://cdn.bitmovin.com/player/android/3/docs/player-core/com.bitmovin.player.api.media/-media-track-role/id.html).
* May be undefined.
* - On iOS and tvOS: `undefined`, as HLS characteristics do not have inherent IDs in this context.
*/
id?: string;
/**
* The URI identifying the scheme used for the role definition.
* - On Android: Corresponds to the native [`MediaTrackRole.schemeIdUri`](https://cdn.bitmovin.com/player/android/3/docs/player-core/com.bitmovin.player.api.media/-media-track-role/scheme-id-uri.html)
* (e.g., "urn:mpeg:dash:role:2011").
* - On iOS and tvOS: predefined URN `urn:hls:characteristic` representing HLS characteristics.
*/
schemeIdUri: string;
/**
* The value of the role within the specified scheme.
* - On Android: Corresponds to the native [`MediaTrackRole.value`](https://cdn.bitmovin.com/player/android/3/docs/player-core/com.bitmovin.player.api.media/-media-track-role/value.html)
* (e.g., "main", "caption", "description").
* - On iOS and tvOS: The raw HLS characteristic string (e.g., "public.accessibility.describes-music-and-sound",
* "public.accessibility.transcribes-spoken-dialog").
*/
value?: string;
}
/**
* Supported subtitle/caption file formats.
* @platform Android, iOS, tvOS
*/
declare enum SubtitleFormat {
/**
* Closed Captioning (CEA) subtitle format.
* @platform Android, iOS, tvOS
*/
CEA = "cea",
/**
* Timed Text Markup Language (TTML) subtitle format.
* @platform Android, iOS, tvOS
*/
TTML = "ttml",
/**
* Web Video Text Tracks Format (WebVTT) subtitle format.
* @platform Android, iOS, tvOS
*/
VTT = "vtt",
/**
* SubRip (SRT) subtitle format.
* @platform Android, iOS, tvOS
*/
SRT = "srt"
}
/**
* Describes a subtitle track.
* @platform Android, iOS, tvOS
*/
interface SubtitleTrack {
/**
* The URL to the timed file, e.g. WebVTT file.
*/
url?: string;
/**
* The label for this track.
*/
label?: string;
/**
* The unique identifier for this track. If no value is provided, a random UUIDv4 will be generated for it.
*/
identifier?: string;
/**
* Specifies the file format to be used by this track.
*/
format?: SubtitleFormat;
/**
* If set to true, this track would be considered as default. Default is `false`.
*/
isDefault?: boolean;
/**
* Tells if a subtitle track is forced. If set to `true` it means that the player should automatically
* select and switch this subtitle according to the selected audio language. Forced subtitles do
* not appear in `Player.getAvailableSubtitles`.
*
* Default is `false`.
*/
isForced?: boolean;
/**
* The IETF BCP 47 language tag associated with this track, e.g. `pt`, `en`, `es` etc.
*/
language?: string;
/**
* An array of {@link MediaTrackRole} objects, each describing a specific role or characteristic of the subtitle track.
* This property provides a unified way to understand track purposes (e.g., for accessibility) across platforms.
*/
roles?: MediaTrackRole[];
}
/**
* A subtitle track that can be added to `SourceConfig.subtitleTracks`.
*/
interface SideLoadedSubtitleTrack extends SubtitleTrack {
url: string;
label: string;
language: string;
format: SubtitleFormat;
}
/**
* Quality definition of a video representation.
*/
interface VideoQuality {
/**
* The id of the media quality.
*/
id: string;
/**
* The label of the media quality that should be exposed to the user.
*/
label?: string;
/**
* The bitrate of the media quality.
*/
bitrate?: number;
/**
* The codec of the media quality.
*/
codec?: string;
/**
* The frame rate of the video quality. If the frame rate is not known or not applicable a value of -1 will be returned.
*/
frameRate?: number;
/**
* The height of the video quality.
*/
height?: number;
/**
* The width of the video quality.
*/
width?: number;
}
/**
* Represents an audio track for a video.
*/
interface AudioTrack {
/**
* The URL to the timed file, e.g. WebVTT file.
*/
url?: string;
/**
* The label for this track.
*/
label?: string;
/**
* The unique identifier for this track. If no value is provided, a random UUIDv4 will be generated for it.
*/
identifier?: string;
/**
* If set to true, this track would be considered as default. Default is `false`.
*/
isDefault?: boolean;
/**
* The IETF BCP 47 language tag associated with this track, e.g. `pt`, `en`, `es` etc.
*/
language?: string;
/**
* An array of {@link MediaTrackRole} objects, each describing a specific role or characteristic of the audio track.
* This property provides a unified way to understand track purposes (e.g., for accessibility) across platforms.
*/
roles?: MediaTrackRole[];
}
interface NativeInstanceConfig {
/**
* Optionally user-defined string `id` for the native instance.
* Used to access a certain native instance from any point in the source code then call
* methods/properties on it.
*
* When left empty, a random `UUIDv4` is generated for it.
* @example
* Accessing or creating the `Player` with `nativeId` equal to `my-player`:
* ```
* const player = new Player({ nativeId: 'my-player' })
* player.play(); // call methods and properties...
* ```
*/
nativeId?: string;
}
declare abstract class NativeInstance<Config extends NativeInstanceConfig> {
/**
* Optionally user-defined string `id` for the native instance, or UUIDv4.
*/
readonly nativeId: string;
/**
* The configuration object used to initialize this instance.
*/
readonly config?: Config;
/**
* Generate UUID in case the user-defined `nativeId` is empty.
*/
constructor(config?: Config);
/**
* Flag indicating whether the native resources of this object have been created internally
* .i.e `initialize` has been called.
*/
abstract isInitialized: boolean;
/**
* Create the native object/resources that will be managed by this instance.
*/
abstract initialize(): void;
/**
* Flag indicating whether the native resources of this object have been disposed .i.e
* `destroy` has been called.
*/
abstract isDestroyed: boolean;
/**
* Dispose the native object/resources created by this instance during `initialize`.
*/
abstract destroy(): void;
}
/**
* Represents a FairPlay Streaming DRM config.
*/
interface FairplayConfig {
/**
* The DRM license acquisition URL.
*/
licenseUrl: string;
/**
* The URL to the FairPlay Streaming certificate of the license server.
*/
certificateUrl?: string;
/**
* A dictionary to specify custom HTTP headers for the license request.
*/
licenseRequestHeaders?: Record<string, string>;
/**
* A dictionary to specify custom HTTP headers for the certificate request.
*/
certificateRequestHeaders?: Record<string, string>;
/**
* A block to prepare the loaded certificate before building SPC data and passing it into the
* system. This is needed if the server responds with anything else than the certificate, e.g. if
* the certificate is wrapped into a JSON object. The server response for the certificate request
* is passed as parameter “as is”.
*
* Note that both the passed `certificate` data and this block return value should be a Base64
* string. So use whatever solution suits you best to handle Base64 in React Native.
*
* @param certificate - Base64 encoded certificate data.
* @returns The processed Base64 encoded certificate.
*/
prepareCertificate?: (certificate: string) => string;
/**
* A block to prepare the data which is sent as the body of the POST license request.
* As many DRM providers expect different, vendor-specific messages, this can be done using
* this user-defined block.
*
* Note that both the passed `message` data and this block return value should be a Base64 string.
* So use whatever solution suits you best to handle Base64 in React Native.
*
* @param message - Base64 encoded message data.
* @param assetId - Stream asset ID.
* @returns The processed Base64 encoded message.
*/
prepareMessage?: (message: string, assetId: string) => string;
/**
* A block to prepare the data which is sent as the body of the POST request for syncing the DRM
* license information.
*
* Note that both the passed `syncMessage` data and this block return value should be a Base64
* string. So use whatever solution suits you best to handle Base64 in React Native.
*
* @param message - Base64 encoded message data.
* @param assetId - Asset ID.
* @returns The processed Base64 encoded sync message.
*/
prepareSyncMessage?: (syncMessage: string, assetId: string) => string;
/**
* A block to prepare the loaded CKC Data before passing it to the system. This is needed if the
* server responds with anything else than the license, e.g. if the license is wrapped into a JSON
* object.
*
* Note that both the passed `license` data and this block return value should be a Base64 string.
* So use whatever solution suits you best to handle Base64 in React Native.
*
* @param license - Base64 encoded license data.
* @returns The processed Base64 encoded license.
*/
prepareLicense?: (license: string) => string;
/**
* A block to prepare the URI (without the skd://) from the HLS manifest before passing it to the
* system.
*
* @param licenseServerUrl - License server URL string.
* @returns The processed license server URL string.
*/
prepareLicenseServerUrl?: (licenseServerUrl: string) => string;
/**
* A block to prepare the `contentId`, which is sent to the FairPlay Streaming license server as
* request body, and which is used to build the SPC data. As many DRM providers expect different,
* vendor-specific messages, this can be done using this user-defined block. The parameter is the
* skd:// URI extracted from the HLS manifest (m3u8) and the return value should be the contentID
* as string.
*
* @param contentId - Extracted content id string.
* @returns The processed contentId.
*/
prepareContentId?: (contentId: string) => string;
}
/**
* Represents a Widevine Streaming DRM config.
* @platform Android, iOS (only for casting).
*/
interface WidevineConfig {
/**
* The DRM license acquisition URL.
*/
licenseUrl: string;
/**
* A map containing the HTTP request headers, or null.
*/
httpHeaders?: Record<string, string>;
/**
* A block to prepare the data which is sent as the body of the POST license request.
* As many DRM providers expect different, vendor-specific messages, this can be done using
* this user-defined block.
*
* Note that both the passed `message` data and this block return value should be a Base64 string.
* So use whatever solution suits you best to handle Base64 in React Native.
*
* @platform Android
*
* @param message - Base64 encoded message data.
* @returns The processed Base64 encoded message.
*/
prepareMessage?: (message: string) => string;
/**
* A block to prepare the loaded CKC Data before passing it to the system. This is needed if the
* server responds with anything else than the license, e.g. if the license is wrapped into a JSON
* object.
*
* Note that both the passed `license` data and this block return value should be a Base64 string.
* So use whatever solution suits you best to handle Base64 in React Native.
*
* @platform Android
*
* @param license - Base64 encoded license data.
* @returns The processed Base64 encoded license.
*/
prepareLicense?: (license: string) => string;
/**
* Set widevine's preferred security level.
*
* @platform Android
*/
preferredSecurityLevel?: string;
/**
* Indicates if the DRM sessions should be kept alive after a source is unloaded.
* This allows DRM sessions to be reused over several different source items with the same DRM configuration as well
* as the same DRM scheme information.
* Default: `false`
*
* @platform Android
*/
shouldKeepDrmSessionsAlive?: boolean;
}
/**
* Represents the general Streaming DRM config.
*/
interface DrmConfig extends NativeInstanceConfig {
/**
* FairPlay specific configuration.
*
* @platform iOS
*/
fairplay?: FairplayConfig;
/**
* Widevine specific configuration.
*
* @platform Android, iOS (only for casting).
*/
widevine?: WidevineConfig;
}
/**
* Represents a native DRM configuration object.
* @internal
*/
declare class Drm extends NativeInstance<DrmConfig> {
/**
* Whether this object's native instance has been created.
*/
isInitialized: boolean;
/**
* Whether this object's native instance has been disposed.
*/
isDestroyed: boolean;
/**
* Allocates the DRM config instance and its resources natively.
*/
initialize: () => void;
/**
* Destroys the native DRM config and releases all of its allocated resources.
*/
destroy: () => void;
/**
* iOS only.
*
* Applies the user-defined `prepareCertificate` function to native's `certificate` data and store
* the result back in `DrmModule`.
*
* Called from native code when `FairplayConfig.prepareCertificate` is dispatched.
*
* @param certificate - Base64 encoded certificate data.
*/
onPrepareCertificate: (certificate: string) => void;
/**
* Applies the user-defined `prepareMessage` function to native's `message` data and store
* the result back in `DrmModule`.
*
* Called from native code when `prepareMessage` is dispatched.
*
* @param message - Base64 encoded message data.
* @param assetId - Optional asset ID. Only sent by iOS.
*/
onPrepareMessage: (message: string, assetId?: string) => void;
/**
* iOS only.
*
* Applies the user-defined `prepareSyncMessage` function to native's `syncMessage` data and
* store the result back in `DrmModule`.
*
* Called from native code when `FairplayConfig.prepareSyncMessage` is dispatched.
*
* @param syncMessage - Base64 encoded sync SPC message data.
*/
onPrepareSyncMessage: (syncMessage: string, assetId: string) => void;
/**
* Applies the user-defined `prepareLicense` function to native's `license` data and store
* the result back in `DrmModule`.
*
* Called from native code when `prepareLicense` is dispatched.
*
* @param license - Base64 encoded license data.
*/
onPrepareLicense: (license: string) => void;
/**
* iOS only.
*
* Applies the user-defined `prepareLicenseServerUrl` function to native's `licenseServerUrl` data
* and store the result back in `DrmModule`.
*
* Called from native code when `FairplayConfig.prepareLicenseServerUrl` is dispatched.
*
* @param licenseServerUrl - The license server URL string.
*/
onPrepareLicenseServerUrl: (licenseServerUrl: string) => void;
/**
* iOS only.
*
* Applies the user-defined `prepareContentId` function to native's `contentId` string
* and store the result back in `DrmModule`.
*
* Called from native code when `FairplayConfig.prepareContentId` is dispatched.
*
* @param contentId - The extracted contentId string.
*/
onPrepareContentId: (contentId: string) => void;
}
/**
* Represents a VTT thumbnail.
*/
interface Thumbnail {
/**
* The start time of the thumbnail.
*/
start: number;
/**
* The end time of the thumbnail.
*/
end: number;
/**
* The raw cue data.
*/
text: string;
/**
* The URL of the spritesheet
*/
url: string;
/**
* The horizontal offset of the thumbnail in its spritesheet
*/
x: number;
/**
* The vertical offset of the thumbnail in its spritesheet
*/
y: number;
/**
* The width of the thumbnail
*/
width: number;
/**
* The height of the thumbnail
*/
height: number;
}
/**
* Types of media that can be handled by the player.
*/
declare enum SourceType {
/**
* Indicates a missing source type.
*/
NONE = "none",
/**
* Indicates media type HLS.
*/
HLS = "hls",
/**
* Indicates media type DASH.
*/
DASH = "dash",
/**
* Indicates media type Progressive MP4.
*/
PROGRESSIVE = "progressive"
}
/**
* The different loading states a {@link Source} instance can be in.
*/
declare enum LoadingState {
/**
* The source is unloaded.
*/
UNLOADED = 0,
/**
* The source is currently loading.
*/
LOADING = 1,
/**
* The source is loaded.
*/
LOADED = 2
}
/**
* Types of SourceOptions.
*/
interface SourceOptions {
/**
* The position where the stream should be started.
* Number can be positive or negative depending on the used `TimelineReferencePoint`.
* Invalid numbers will be corrected according to the stream boundaries.
* For VOD this is applied at the time the stream is loaded, for LIVE when playback starts.
*/
startOffset?: number;
/**
* Sets the Timeline reference point to calculate the startOffset from.
* Default for live: `TimelineReferencePoint.END`.
* Default for VOD: `TimelineReferencePoint.START`.
*/
startOffsetTimelineReference?: TimelineReferencePoint;
}
/**
Timeline reference point to calculate SourceOptions.startOffset from.
Default for live: TimelineReferencePoint.EBD Default for VOD: TimelineReferencePoint.START.
*/
declare enum TimelineReferencePoint {
/**
* Relative offset will be calculated from the beginning of the stream or DVR window.
*/
START = "start",
/**
* Relative offset will be calculated from the end of the stream or the live edge in case of a live stream with DVR window.
*/
END = "end"
}
/**
* Represents a source configuration that be loaded into a player instance.
*/
interface SourceConfig extends NativeInstanceConfig {
/**
* The url for this source configuration.
*/
url: string;
/**
* The `SourceType` for this configuration.
*/
type?: SourceType;
/**
* The title of the video source.
*/
title?: string;
/**
* The description of the video source.
*/
description?: string;
/**
* The URL to a preview image displayed until the video starts.
*/
poster?: string;
/**
* Indicates whether to show the poster image during playback.
* Useful, for example, for audio-only streams.
*/
isPosterPersistent?: boolean;
/**
* The DRM config for the source.
*/
drmConfig?: DrmConfig;
/**
* External subtitle tracks to be added into the player.
*/
subtitleTracks?: SideLoadedSubtitleTrack[];
/**
* External thumbnails to be added into the player.
*/
thumbnailTrack?: string;
/**
* The optional custom metadata. Also sent to the cast receiver when loading the Source.
*/
metadata?: Record<string, string>;
/**
* The `SourceOptions` for this configuration.
*/
options?: SourceOptions;
/**
* The `SourceMetadata` for the {@link Source} to setup custom analytics tracking
*/
analyticsSourceMetadata?: SourceMetadata;
}
/**
* The remote control config for a source.
* @platform iOS
*/
interface SourceRemoteControlConfig {
/**
* The `SourceConfig` for casting.
* Enables to play different content when casting.
* This can be useful when the remote playback device supports different streaming formats,
* DRM systems, etc. than the local device.
* If not set, the local source config will be used for casting.
*/
castSourceConfig?: SourceConfig | null;
}
/**
* Represents audio and video content that can be loaded into a player.
*/
declare class Source extends NativeInstance<SourceConfig> {
/**
* The native DRM config reference of this source.
*/
private drm?;
/**
* The remote control config for this source.
* This is only supported on iOS.
*
* @platform iOS
*/
remoteControl: SourceRemoteControlConfig | null;
/**
* Whether the native {@link Source} object has been created.
*/
isInitialized: boolean;
/**
* Whether the native {@link Source} object has been disposed.
*/
isDestroyed: boolean;
/**
* Allocates the native {@link Source} instance and its resources natively.
*/
initialize: () => void;
/**
* Destroys the native {@link Source} and releases all of its allocated resources.
*/
destroy: () => void;
/**
* The duration of the source in seconds if it’s a VoD or `INFINITY` if it’s a live stream.
* Default value is `0` if the duration is not available or not known.
*/
duration: () => Promise<number>;
/**
* Whether the source is currently active in a player (i.e. playing back or paused).
* Only one source can be active in the same player instance at any time.
*/
isActive: () => Promise<boolean>;
/**
* Whether the source is currently attached to a player instance.
*/
isAttachedToPlayer: () => Promise<boolean>;
/**
* Metadata for the currently loaded source.
*/
metadata: () => Promise<Record<string, any> | null>;
/**
* Set metadata for the currently loaded source.
* Setting the metadata to `null` clears the metadata object in native source.
*
* @param metadata metadata to be set.
*/
setMetadata: (metadata: Record<string, any> | null) => void;
/**
* The current `LoadingState` of the source.
*/
loadingState: () => Promise<LoadingState>;
/**
* @returns a `Thumbnail` for the specified playback time if available.
* Supported thumbnail formats are:
* - `WebVtt` configured via {@link SourceConfig.thumbnailTrack}, on all supported platforms
* - HLS `Image Media Playlist` in the multivariant playlist, Android-only
* - DASH `Image Adaptation Set` as specified in DASH-IF IOP, Android-only
* If a `WebVtt` thumbnail track is provided, any potential in-manifest thumbnails are ignored on Android.
*
* @param time - The time in seconds for which to retrieve the thumbnail.
*/
getThumbnail: (time: number) => Promise<Thumbnail | null>;
}
/**
* Available HTTP request types.
*/
declare enum HttpRequestType {
ManifestDash = "manifest/dash",
ManifestHlsMaster = "manifest/hls/master",
ManifestHlsVariant = "manifest/hls/variant",
ManifestSmooth = "manifest/smooth",
MediaProgressive = "media/progressive",
MediaAudio = "media/audio",
MediaVideo = "media/video",
MediaSubtitles = "media/subtitles",
MediaThumbnails = "media/thumbnails",
DrmLicenseFairplay = "drm/license/fairplay",
DrmCertificateFairplay = "drm/certificate/fairplay",
DrmLicenseWidevine = "drm/license/widevine",
KeyHlsAes = "key/hls/aes",
Unknown = "unknown"
}
/**
* Base64-encoded string representing the HTTP request body.
*/
type HttpRequestBody = string;
/** Represents an HTTP request. */
interface HttpRequest {
/** The {@link HttpRequestBody} to send to the server. */
body?: HttpRequestBody;
/**
* The HTTP Headers of the request.
* Entries are expected to have the HTTP header as the key and its string content as the value.
*/
headers: Record<string, string>;
/** The HTTP method of the request. */
method: string;
/** The URL of the request. */
url: string;
}
/**
* Base64-encoded string representing the HTTP response body.
*/
type HttpResponseBody = string;
/** Represents an HTTP response. */
interface HttpResponse {
/** The {@link HttpRequestBody} of the response. */
body?: HttpResponseBody;
/**
* The HTTP Headers of the response.
* Entries are expected to have the HTTP header as the key and its string content as the value.
*/
headers: Record<string, string>;
/** The corresponding request object of the response. */
request: HttpRequest;
/** The HTTP status code of the response. */
status: number;
/** The URL of the response. May differ from {@link HttpRequest.url} when redirects have happened. */
url: string;
}
/**
* The network API gives the ability to influence network requests.
* It enables preprocessing requests and preprocessing responses.
*/
interface NetworkConfig extends NativeInstanceConfig {
/**
* Called before an HTTP request is made.
* Can be used to change request parameters.
*
* @param type Type of the request to be made.
* @param request The HTTP request to process.
* @returns A Promise that resolves to an `HttpRequest` object.
* - If the promise resolves, the player will use the processed request.
* - If the promise rejects, the player will fall back to using the original request.
*
* @examples
* ```
* const requestCallback = (type: HttpRequestType, request: HttpRequest) => {
* // Access current properties
*
* console.log(JSON.stringify(type));
* console.log(JSON.stringify(request));
*
* // Modify the request
*
* request.headers['New-Header'] = 'val';
* request.method = 'GET';
*
* // Return the processed request via a Promise
*
* const processed: HttpRequest = {
* body: request.body,
* headers: request.headers,
* method: request.method,
* url: request.url,
* };
* return Promise.resolve(processed);
* };
*
* const player = usePlayer({
* networkConfig: {
* preprocessHttpRequest: requestCallback,
* },
* });
* ```
*/
preprocessHttpRequest?: (type: HttpRequestType, request: HttpRequest) => Promise<HttpRequest>;
/**
* Called before an HTTP response is accessed by the player.
* Can be used to access or change the response.
*
* @param type Type of the corresponding request object of the response.
* @param response The HTTP response to process.
* @returns A Promise that resolves to an `HttpResponse` object.
* - If the promise resolves, the player will use the processed response.
* - If the promise rejects, the player will fall back to using the original response.
*
* @example
* ```
* const responseCallback = (type: HttpRequestType, response: HttpResponse) => {
* // Access response properties
*
* console.log(JSON.stringify(type));
* console.log(JSON.stringify(response));
*
* // Modify the response
*
* response.headers['New-Header'] = 'val';
* response.url = response.request.url; // remove eventual redirect changes
*
* // Return the processed response via a Promise
*
* const processed: HttpResponse = {
* body: response.body,
* headers: response.headers,
* request: response.request,
* status: response.status,
* url: response.url,
* };
* return Promise.resolve(processed);
* };
*
* // Properly attach the callback to the config
* const player = usePlayer({
* networkConfig: {
* preprocessHttpResponse: responseCallback,
* },
* });
* ```
*/
preprocessHttpResponse?: (type: HttpRequestType, response: HttpResponse) => Promise<HttpResponse>;
}
/**
* Base event type for all events.
*/
interface Event {
/**
* This event name as it is on the native side.
*/
name: string;
/**
* The UNIX timestamp in which this event happened.
*/
timestamp: number;
}
/**
* Base event type for error and warning events.
*/
interface ErrorEvent extends Event {
/**
* Error/Warning's code number.
*/
code?: number;
/**
* Error/Warning's localized message.
*/
message: string;
/**
* Underlying data emitted with the error or warning.
*/
data?: Record<string, any>;
}
/**
* Emitted when a source is loaded into the player.
* Seeking and time shifting are allowed as soon as this event is seen.
*/
interface PlayerActiveEvent extends Event {
}
/**
* Emitted when a player error occurred.
*/
interface PlayerErrorEvent extends ErrorEvent {
}
/**
* Emitted when a player warning occurred.
*/
interface PlayerWarningEvent extends ErrorEvent {
}
/**
* Emitted when the player is destroyed.
*/
interface DestroyEvent extends Event {
}
/**
* Emitted when the player is muted.
*/
interface MutedEvent extends Event {
}
/**
* Emitted when the player is unmuted.
*/
interface UnmutedEvent extends Event {
}
/**
* Emitted when the player is ready for immediate playback, because initial audio/video
* has been downloaded.
*/
interface ReadyEvent extends Event {
}
/**
* Emitted when the player is paused.
*/
interface PausedEvent extends Event {
/**
* The player's playback time from when this event happened.
*/
time: number;
}
/**
* Emitted when the player received an intention to start/resume playback.
*/
interface PlayEvent extends Event {
/**
* The player's playback time from when this event happened.
*/
time: number;
}
/**
* Emitted when playback has started.
*/
interface PlayingEvent extends Event {
/**
* The player's playback time from when this event happened.
*/
time: number;
}
/**
* Emitted when the playback of the current media has finished.
*/
interface PlaybackFinishedEvent extends Event {
}
/**
* Source object representation the way it appears on event's payloads such as `SeekEvent`, for example.
*
* This interface only type hints what should be the shape of a {@link Source} object inside an event's
* payload during runtime so it has no direct relation with the `Source` class present in `src/source.ts`.
*
* Do not mistake it for a `NativeInstance` type.
*/
interface EventSource {
/**
* Event's source duration in seconds.
*/
duration: number;
/**
* Whether this event's source is currently active in a player.
*/
isActive: boolean;
/**
* Whether this event's source is currently attached to a player instance.
*/
isAttachedToPlayer: boolean;
/**
* Metadata for this event's source.
*/
metadata?: Record<string, any>;
/**
* The current {@link LoadingState} of the source.
*/
loadingState: LoadingState;
}
/**
* Represents a seeking position.
*/
interface SeekPosition {
/**
* The relevant {@link Source}.
*/
source: EventSource;
/**
* The position within the {@link Source} in seconds.
*/
time: number;
}
/**
* Emitted when the player is about to seek to a new position.
* This event only applies to VoD streams.
* When looking for an equivalent for live streams, the {@link TimeShiftEvent} is relevant.
*/
interface SeekEvent extends Event {
/**
* Origin source metadata.
*/
from: SeekPosition;
/**
* Target source metadata.
*/
to: SeekPosition;
}
/**
* Emitted when seeking has finished and data to continue playback is available.
* This event only applies to VoD streams.
* When looking for an equivalent for live streams, the {@link TimeShiftedEvent} is relevant.
*/
interface SeekedEvent extends Event {
}
/**
* Emitted when the player starts time shifting.
* This event only applies to live streams.
* When looking for an equivalent for VoD streams, the {@link SeekEvent} is relevant.
*/
interface TimeShiftEvent extends Event {
/**
* The position from which we start the time shift
*/
position: number;
/**
* The position to which we want to jump for the time shift
*/
targetPosition: number;
}
/**
* Emitted when time shifting has finished and data is available to continue playback.
* This event only applies to live streams.
* When looking for an equivalent for VoD streams, the {@link SeekedEvent} is relevant.
*/
interface TimeShiftedEvent extends Event {
}
/**
* Emitted when the player begins to stall and to buffer due to an empty buffer.
*/
interface StallStartedEvent extends Event {
}
/**
* Emitted when the player ends stalling, due to enough data in the buffer.
*/
interface StallEndedEvent extends Event {
}
/**
* Emitted when the current playback time has changed.
*/
interface TimeChangedEvent extends Event {
/**
* The player's playback time from when this event happened.
*/
currentTime: number;
}
/**
* Emitted when a new source loading has started.
*/
interface SourceLoadEvent extends Event {
/**
* Source that is about to load.
*/
source: EventSource;
}
/**
* Emitted when a new source is loaded.
* This does not mean that the source is immediately ready for playback.
* {@link ReadyEvent} indicates the player is ready for immediate playback.
*/
interface SourceLoadedEvent extends Event {
/**
* Source that was loaded into player.
*/
source: EventSource;
}
/**
* Emitted when the current source has been unloaded.
*/
interface SourceUnloadedEvent extends Event {
/**
* Source that was unloaded from player.
*/
source: EventSource;
}
/**
* Emitted when a source error occurred.
*/
interface SourceErrorEvent extends ErrorEvent {
}
/**
* Emitted when a source warning occurred.
*/
interface SourceWarningEvent extends ErrorEvent {
}
/**
* Emitted when a new audio track is added to the player.
*/
interface AudioAddedEvent extends Event {
/**
* Audio track that has been added.
*/
audioTrack: AudioTrack;
}
/**
* Emitted when the player's selected audio track has changed.
*/
interface AudioChangedEvent extends Event {
/**
* Audio track that was previously selected.
*/
oldAudioTrack: AudioTrack;
/**
* Audio track that is selected now.
*/
newAudioTrack: AudioTrack;
}
/**
* Emitted when an audio track is removed from the player.
*/
interface AudioRemovedEvent extends Event {
/**
* Audio track that has been removed.
*/
audioTrack: AudioTrack;
}
/**
* Emitted when a new subtitle track is added to the player.
*/
interface SubtitleAddedEvent extends Event {
/**
* Subtitle track that has been added.
*/
subtitleTrack: SubtitleTrack;
}
/**
* Emitted when a subtitle track is removed from the player.
*/
interface SubtitleRemovedEvent extends Event {
/**
* Subtitle track that has been removed.
*/
subtitleTrack: SubtitleTrack;
}
/**
* Emitted when the player's selected subtitle track has changed.
*/
interface SubtitleChangedEvent extends Event {
/**
* Subtitle track that was previously selected.
*/
oldSubtitleTrack: SubtitleTrack;
/**
* Subtitle track that is selected now.
*/
newSubtitleTrack: SubtitleTrack;
}
/**
* Emitted when the player enters Picture in Picture mode.
*
* @platform iOS, Android
*/
interface PictureInPictureEnterEvent extends Event {
}
/**
* Emitted when the player exits Picture in Picture mode.
*
* @platform iOS, Android
*/
interface PictureInPictureExitEvent extends Event {
}
/**
* Emitted when the player has finished entering Picture in Picture mode on iOS.
*
* @platform iOS
*/
interface PictureInPictureEnteredEvent extends Event {
}
/**
* Emitted when the player has finished exiting Picture in Picture mode on iOS.
*
* @platform iOS
*/
interface PictureInPictureExitedEvent extends Event {
}
/**
* Emitted when the fullscreen functionality has been enabled.
*
* @platform iOS, Android
*/
interface FullscreenEnabledEvent extends Event {
}
/**
* Emitted when the fullscreen functionality has been disabled.
*
* @platform iOS, Android
*/
interface FullscreenDisabledEvent extends Event {
}
/**
* Emitted when the player enters fullscreen mode.
*
* @platform iOS, Android
*/
interface FullscreenEnterEvent extends Event {
}
/**
* Emitted when the player exits fullscreen mode.
*
* @platform iOS, Android
*/
interface FullscreenExitEvent extends Event {
}
/**
* Emitted when the availability of the Picture in Picture mode changed on Android.
*
* @platform Android
*/
interface PictureInPictureAvailabilityChang