/** * Copyright 2015 CANAL+ Group * * Licensed under the Apache License, Version 2.0 (the "License");publicapi * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import type { IInbandEvent, IBufferedChunk, IBufferType } from "../../core/types"; import type { IErrorCode, IErrorType } from "../../errors"; import type { IFeature } from "../../features"; import type { IAdaptationMetadata, IManifestMetadata, IRepresentationMetadata } from "../../manifest"; import type { IAudioRepresentation, IAudioTrack, IAudioTrackSetting, IAvailableAudioTrack, IAvailableTextTrack, IAvailableVideoTrack, IBrokenRepresentationsLockContext, IConstructorOptions, IKeySystemConfigurationOutput, IKeySystemOption, ILoadVideoOptions, ILockedAudioRepresentationsSettings, ILockedVideoRepresentationsSettings, ITrackUpdateEventPayload, IRepresentationListUpdateContext, IPeriod, IPeriodChangeEvent, IPlayerError, IPlayerState, IPositionUpdate, IStreamEvent, ITextTrack, IVideoRepresentation, ITextTrackSetting, IVideoTrack, IVideoTrackSetting, IModeInformation, IWorkerSettings } from "../../public_types"; import type { IListener } from "../../utils/event_emitter"; import EventEmitter from "../../utils/event_emitter"; import type Logger from "../../utils/logger"; /** * @class Player * @extends EventEmitter */ declare class Player extends EventEmitter { /** Current version of the RxPlayer. */ static version: string; /** Current version of the RxPlayer. */ readonly version: string; /** * Store all video elements currently in use by an RxPlayer instance. * This is used to check that a video element is not shared between multiple instances. * Use of a WeakSet ensure the object is garbage collected if it's not used anymore. */ private static _priv_currentlyUsedVideoElements; /** * Media element attached to the RxPlayer. * Set to `null` when the RxPlayer is disposed. */ videoElement: HTMLMediaElement | null; /** Logger the RxPlayer uses. */ readonly log: Logger; /** * Current state of the RxPlayer. * Please use `getPlayerState()` instead. */ state: IPlayerState; /** * Emit when the the RxPlayer is not needed anymore and thus all resources * used for its normal functionment can be freed. * The player will be unusable after that. */ private readonly _destroyCanceller; /** * Contains `true` when the previous content is cleaning-up, `false` when it's * done. * A new content cannot be launched until it stores `false`. */ private readonly _priv_contentLock; /** * The speed that should be applied to playback. * Used instead of videoElement.playbackRate to allow more flexibility. */ private readonly _priv_speed; /** Store buffer-related options used needed when initializing a content. */ private readonly _priv_bufferOptions; /** Information on the current bitrate settings. */ private readonly _priv_bitrateInfos; private _priv_worker; /** * Current fatal error which STOPPED the player. * `null` if no fatal error was received for the current or last content. */ private _priv_currentError; /** * Information about the current content being played. * `null` when no content is currently loading or loaded. */ private _priv_contentInfos; /** If `true` trickMode video tracks will be chosen if available. */ private _priv_preferTrickModeTracks; /** Refer to last picture in picture event received. */ private _priv_pictureInPictureRef; /** Store wanted configuration for the `videoResolutionLimit` option. */ private readonly _priv_videoResolutionLimit; /** Store wanted configuration for the `throttleVideoBitrateWhenHidden` option. */ private readonly _priv_throttleVideoBitrateWhenHidden; /** * Store last state of various values sent as events, to avoid re-triggering * them multiple times in a row. * * All those events are linked to the content being played and can be cleaned * on stop. */ private _priv_contentEventsMemory; /** * Information that can be relied on once `reload` is called. * It should refer to the last content being played. */ private _priv_reloadingMetadata; /** * Store last value of autoPlay, from the last load or reload. */ private _priv_lastAutoPlay; /** All possible Error types emitted by the RxPlayer. */ static get ErrorTypes(): Record; /** All possible Error codes emitted by the RxPlayer. */ static get ErrorCodes(): Record; /** * Current log level. * Update current log level. * Should be either (by verbosity ascending): * - "NONE" * - "ERROR" * - "WARNING" * - "INFO" * - "DEBUG" * Any other value will be translated to "NONE". */ static get LogLevel(): string; static set LogLevel(logLevel: string); /** * Add feature(s) to the RxPlayer. * @param {Array.} featureList - Features wanted. */ static addFeatures(featureList: IFeature[]): void; /** * Register the video element to the set of elements currently in use. * @param videoElement the video element to register. * @throws Error - Throws if the element is already used by another player instance. */ private static _priv_registerVideoElement; /** * Deregister the video element of the set of elements currently in use. * @param videoElement the video element to deregister. */ static _priv_deregisterVideoElement(videoElement: HTMLMediaElement): void; /** * @constructor * @param {Object} options */ constructor(options?: IConstructorOptions); /** * TODO returns promise? * @param {Object} workerSettings */ attachWorker(workerSettings: IWorkerSettings): Promise; /** * Returns information on which "mode" the RxPlayer is running for the current * content (e.g. main logic running in a WebWorker or not, are we in * directfile mode...). * * Returns `null` if no content is loaded. * @returns {Object|null} */ getCurrentModeInformation(): IModeInformation | null; /** * Register a new callback for a player event event. * * @param {string} evt - The event to register a callback to * @param {Function} fn - The callback to call as that event is triggered. * The callback will take as argument the eventual payload of the event * (single argument). */ addEventListener(evt: TEventName, fn: IListener): void; /** * Stop the playback for the current content. */ stop(): void; /** * Free the resources used by the player. * /!\ The player cannot be "used" anymore after this method has been called. */ dispose(): void; /** * Load a new video. * @param {Object} opts */ loadVideo(opts: ILoadVideoOptions): void; /** * Reload the last loaded content. * @param {Object} reloadOpts */ reload(reloadOpts?: { reloadAt?: { position?: number; relative?: number; }; keySystems?: IKeySystemOption[]; autoPlay?: boolean; }): void; createDebugElement(element: HTMLElement): { dispose(): void; }; /** * From given options, initialize content playback. * @param {Object} options */ private _priv_initializeContentPlayback; /** * Returns fatal error if one for the current content. * null otherwise. * @returns {Object|null} - The current Error (`null` when no error). */ getError(): Error | null; /** * Returns the media DOM element used by the player. * You should not its HTML5 API directly and use the player's method instead, * to ensure a well-behaved player. * @returns {HTMLMediaElement|null} - The HTMLMediaElement used (`null` when * disposed) */ getVideoElement(): HTMLMediaElement | null; /** * Returns the player's current state. * @returns {string} - The current Player's state */ getPlayerState(): string; /** * Returns true if a content is loaded. * @returns {Boolean} - `true` if a content is loaded, `false` otherwise. */ isContentLoaded(): boolean; /** * Returns true if the player is buffering. * @returns {Boolean} - `true` if the player is buffering, `false` otherwise. */ isBuffering(): boolean; /** * Returns the play/pause status of the player : * - when `LOADING` or `RELOADING`, returns the scheduled play/pause condition * for when loading is over, * - in other states, returns the `