nsplayer
Version:
NSPlayer, a player which supports quality list of dash and hls
114 lines (113 loc) • 4.2 kB
TypeScript
import { Disposable, IDisposable, Event, Emitter } from '@newstudios/common';
import { BasePlayerWithEvent } from './types';
export interface NSPlayerOptions {
el?: HTMLElement;
}
export interface FullscreenFallbackOptions {
/** @default never fallback to native fullscreen */
fallback?: 'native' | 'never';
}
export interface RequestFullscreenOptions extends FullscreenFallbackOptions, FullscreenOptions {
}
export interface IBasePlayer extends IDisposable {
video: HTMLVideoElement | null;
toggle(): void;
togglePictureInPicture(): void;
requestPictureInPicture(): Promise<PictureInPictureWindow>;
exitPictureInPicture(): Promise<void>;
readonly supportPictureInPicture: boolean;
readonly pictureInPicture: boolean;
toggleFullscreen(options?: FullscreenFallbackOptions): void;
requestFullscreen(options?: RequestFullscreenOptions): Promise<void>;
exitFullscreen(options?: FullscreenFallbackOptions): Promise<void>;
readonly fullscreen: boolean;
toggleNativeFullscreen(): void;
requestNativeFullscreen(): void;
exitNativeFullscreen(): void;
readonly nativeFullscreen: boolean;
readonly onAutoPlayError: Event<globalThis.Event>;
readonly onLoopChange: Event<globalThis.Event>;
}
/**
* Base Player that delegates to the video property within the player
*/
export interface BasePlayer extends BasePlayerWithEvent {
/** video delegation begin */
poster: string;
playsInline: boolean;
readonly videoHeight: number;
readonly videoWidth: number;
autoplay: boolean;
buffered: TimeRanges;
controls: boolean;
crossOrigin: string | null;
readonly currentSrc: string;
currentTime: number;
readonly duration: number;
readonly ended: boolean;
readonly error: MediaError | null;
mediaKeys: MediaKeys | null;
muted: boolean;
readonly networkState: number;
readonly paused: boolean;
playbackRate: number;
defaultPlaybackRate: number;
defaultInitialBitrate: number;
readonly played: TimeRanges;
preload: string;
readonly readyState: number;
readonly seekable: TimeRanges;
readonly seeking: boolean;
volume: number;
getVideoPlaybackQuality(): VideoPlaybackQuality;
addTextTrack(kind: TextTrackKind, label?: string | undefined, language?: string | undefined): TextTrack;
canPlayType(type: string): CanPlayTypeResult;
load(): void;
pause(): void;
play(): Promise<void>;
setMediaKeys(mediaKeys: MediaKeys | null): Promise<void>;
}
export declare abstract class BasePlayer extends Disposable implements IBasePlayer {
private _video;
private _disposableVideo;
protected readonly _onAutoPlayError: Emitter<globalThis.Event>;
readonly onAutoPlayError: Event<globalThis.Event>;
protected readonly _onLoopChange: Emitter<globalThis.Event>;
readonly onLoopChange: Event<globalThis.Event>;
private _paused;
private _loop;
abstract get fullscreen(): boolean;
abstract requestFullscreen(options?: RequestFullscreenOptions | undefined): Promise<void>;
set loop(loop: boolean);
get loop(): boolean;
defaultInitialBitrate: number;
exitFullscreen({ fallback }?: {
fallback?: string | undefined;
}): Promise<void>;
toggleFullscreen({ fallback }?: {
fallback?: string | undefined;
}): void;
exitNativeFullscreen(): void;
requestNativeFullscreen(): void;
toggleNativeFullscreen(): void;
get supportFullscreen(): boolean;
get supportNativeFullscreen(): boolean;
get nativeFullscreen(): boolean;
get pictureInPicture(): boolean;
requestPictureInPicture(): Promise<PictureInPictureWindow>;
exitPictureInPicture(): Promise<void>;
get supportPictureInPicture(): boolean;
togglePictureInPicture(): void;
get video(): HTMLVideoElement | null;
set video(video: HTMLVideoElement | null);
private _registerVideoListeners;
/**
* get inner HTMLVideoElement, throw error if video is null
*/
protected withVideo(): HTMLVideoElement;
toggle(): void;
protected reset(): void;
get bufferedTime(): number;
private _nextSeek;
fastSeek(time: number): void;
}