/** * https://developers.google.com/youtube/iframe_api_reference * @fileoverview JSDoc type definitions for the YouTube IFrame Player API. * This file provides full IntelliSense/autocomplete for the global `window.YT` object. * @module youtube-api-docs */ export type YTPlayerState = -1 | 0 | 1 | 2 | 3 | 5; export type YTPlayerErrors = 2 | 5 | 100 | 101 | 150; export type YTQuality = 'small' | 'medium' | 'large' | 'hd720' | 'hd1080' | 'highres'; export type YTSphericalProperties = { /** * - Horizontal angle of view [0, 360]. */ yaw: number; /** * - Vertical angle of view [-90, 90]. */ pitch: number; /** * - Rotational angle [-180, 180]. */ roll: number; /** * - Field of view [30, 120]. */ fov: number; }; export type YouTubePlayerEventBase = { /** * - The player object that emitted the event. */ target: YouTubePlayer; }; export type OnReadyEvent = (event: YouTubePlayerEventBase) => void; export type OnStateChangeEvent = (event: YouTubePlayerEventBase & { data: YTPlayerState; }) => void; export type OnErrorEvent = (event: YouTubePlayerEventBase & { data: YTPlayerErrors; }) => void; export type OnPlaybackQualityChangeEvent = (event: YouTubePlayerEventBase & { data: YTQuality; }) => void; export type OnPlaybackRateChangeEvent = (event: YouTubePlayerEventBase & { data: number; }) => void; export type OnApiChangeEvent = (event: YouTubePlayerEventBase & { data: any; }) => void; export type OnAutoplayBlockedEvent = (event: YouTubePlayerEventBase) => void; export type YTPlayerOptionsEvents = { /** * - Called when the player is ready. */ onReady?: OnReadyEvent; /** * - Called when the state changes. */ onStateChange?: OnStateChangeEvent; /** * - Called when an error occurs. */ onError?: OnErrorEvent; /** * - Called when quality changes. */ onPlaybackQualityChange?: OnPlaybackQualityChangeEvent; /** * - Called when playback rate changes. */ onPlaybackRateChange?: OnPlaybackRateChangeEvent; /** * - Called when the API module changes. */ onApiChange?: OnApiChangeEvent; /** * - Called when autoplay is blocked. */ onAutoplayBlocked?: OnAutoplayBlockedEvent; }; export type YTPlayerOptions = { /** * - Desired width of the player frame in pixels. */ width?: number | string; /** * - Desired height of the player frame in pixels. */ height?: number | string; /** * - The unique identifier for the YouTube video to load. */ videoId?: string; /** * - Additional configuration parameters passed to the player. */ playerVars?: Record; /** * - An object containing event listeners to handle specific player events. */ events?: YTPlayerOptionsEvents; }; export type EventNames = 'onReady' | 'onStateChange' | 'onError' | 'onPlaybackQualityChange' | 'onPlaybackRateChange' | 'onApiChange' | 'onAutoplayBlocked'; export type YTPlaylistOptions = { /** * - Specifies whether to use a standard playlist or user uploads feed. */ listType?: 'playlist' | 'user_uploads'; /** * - The ID of the target playlist or an array containing multiple video IDs. */ list: string | string[]; /** * - The zero-based index of the first video that should be played from the list. */ index?: number; /** * - The specific time in seconds where the playback of the first video should begin. */ startSeconds?: number; }; export type VideoByUrlOptions = { /** * - The complete URL pointing to the desired YouTube video resource. */ mediaContentUrl: string; /** * - Optional time in seconds to begin playback from within the video. */ startSeconds?: number; /** * - Optional time in seconds when playback should stop within the video. */ endSeconds?: number; }; export type VideoByIdOptions = { /** * - The unique identifier of the target YouTube video. */ videoId: string; /** * - Optional time in seconds to begin playback from within the video. */ startSeconds?: number; /** * - Optional time in seconds when playback should stop within the video. */ endSeconds?: number; }; export type VideoData = { /** * - Whether DVR capabilities are permitted for live content. */ allowLiveDvr: boolean | null; /** * - The name or ID of the video creator. */ author: string | null; /** * - Indicates if the video can be played in the background while minimized. */ backgroundable: boolean | null; /** * - Content Protection Network identifier. */ cpn: string | null; /** * - A specific error code if playback failed. */ errorCode: number | null; /** * - An ID related to a specific content event. */ eventId: string | null; /** * - Flag indicating if the progress bar has defined start/end boundaries. */ hasProgressBarBoundaries: boolean | null; /** * - Indicates if the video belongs to a list or series. */ isListed: boolean | null; /** * - True if the content is currently streaming live. */ isLive: boolean | null; /** * - Flag indicating if manifest files are not being used for streaming. */ isManifestless: boolean | null; /** * - Indicates support for multiple audio channels. */ isMultiChannelAudio: boolean | null; /** * - Overall flag indicating the video can be played by the player. */ isPlayable: boolean | null; /** * - True if the content is a scheduled premiere. */ isPremiere: boolean | null; /** * - Whether random access seeking within the video is allowed. */ isSeekable: boolean | null; /** * - Indicates if it is a windowed live event. */ isWindowedLive: boolean | null; /** * - Indicator of Interactivity Content Tracking tag. */ itct: string | null; /** * - Duration in milliseconds for paid content overlays. */ paidContentOverlayDurationMs: number | null; /** * - Content Protection Network response identifier from the player itself. */ playerResponseCpn: string | null; /** * - UTC time in milliseconds for the end of the video's progress bar. */ progressBarEndPositionUtcTimeMillis: number | null; /** * - UTC time in milliseconds for the start of the video's progress bar. */ progressBarStartPositionUtcTimeMillis: number | null; /** * - The descriptive title of the video. */ title: string | null; /** * - The unique ID string of the video content. */ video_id: string | null; }; /** * Represents the current state of the player. * @typedef {-1|0|1|2|3|5} YTPlayerState * @property {-1} UNSTARTED - The video has not been started. * @property {0} ENDED - The video has ended. * @property {1} PLAYING - The video is playing. * @property {2} PAUSED - The video is paused. * @property {3} BUFFERING - The video is buffering. * @property {5} CUED - The video is cued and ready to play. */ /** * Represents the player error codes. * @typedef {2|5|100|101|150} YTPlayerErrors * @property {2} INVALIDPARAM - The request contains an invalid parameter value (e.g., invalid video ID). * @property {5} INVALIDPLAYER - The content cannot be played in an HTML5 player or an HTML5 error occurred. * @property {100} NOTFOUND - The requested video was not found (removed or private). * @property {101} NOTALLOWED - The owner does not allow playback in embedded players. * @property {150} NOTALLOWED_REDUNDANT - Same as 101. */ /** * The playback quality string. * @typedef {'small'|'medium'|'large'|'hd720'|'hd1080'|'highres'} YTQuality */ /** * Properties for 360° video playback, defining the viewing angle. * @typedef {Object} YTSphericalProperties * @property {number} yaw - Horizontal angle of view [0, 360]. * @property {number} pitch - Vertical angle of view [-90, 90]. * @property {number} roll - Rotational angle [-180, 180]. * @property {number} fov - Field of view [30, 120]. */ /** * Base structure for all YouTube Player Events. * @typedef {Object} YouTubePlayerEventBase * @property {YouTubePlayer} target - The player object that emitted the event. */ /** * Called when the player is ready to accept commands. * @typedef {(event: YouTubePlayerEventBase) => void} OnReadyEvent */ /** * Called when the video playback state changes (e.g., playing, paused). * @typedef {(event: YouTubePlayerEventBase & { data: YTPlayerState }) => void} OnStateChangeEvent */ /** * Called when an error occurs during video processing or playback. * @typedef {(event: YouTubePlayerEventBase & { data: YTPlayerErrors }) => void} OnErrorEvent */ /** * Called specifically when the playback quality setting is updated. * @typedef {(event: YouTubePlayerEventBase & { data: YTQuality }) => void} OnPlaybackQualityChangeEvent */ /** * Called when the video's speed (playback rate) changes or is set. * @typedef {(event: YouTubePlayerEventBase & { data: number }) => void} OnPlaybackRateChangeEvent */ /** * Called when a change occurs within the API module itself. * @typedef {(event: YouTubePlayerEventBase & { data: any }) => void} OnApiChangeEvent */ /** * Called when automatic playback is specifically blocked by the browser or platform rules. * @typedef {(event: YouTubePlayerEventBase) => void} OnAutoplayBlockedEvent */ /** * Container object for configuring event listeners on the player instance. * @typedef {Object} YTPlayerOptionsEvents * @property {OnReadyEvent} [onReady] - Called when the player is ready. * @property {OnStateChangeEvent} [onStateChange] - Called when the state changes. * @property {OnErrorEvent} [onError] - Called when an error occurs. * @property {OnPlaybackQualityChangeEvent} [onPlaybackQualityChange] - Called when quality changes. * @property {OnPlaybackRateChangeEvent} [onPlaybackRateChange] - Called when playback rate changes. * @property {OnApiChangeEvent} [onApiChange] - Called when the API module changes. * @property {OnAutoplayBlockedEvent} [onAutoplayBlocked] - Called when autoplay is blocked. */ /** * Configuration options for initializing the YouTube Player instance. * @typedef {Object} YTPlayerOptions * @property {number|string} [width=640] - Desired width of the player frame in pixels. * @property {number|string} [height=390] - Desired height of the player frame in pixels. * @property {string} [videoId] - The unique identifier for the YouTube video to load. * @property {Object} [playerVars] - Additional configuration parameters passed to the player. * @property {YTPlayerOptionsEvents} [events] - An object containing event listeners to handle specific player events. */ /** * List of valid names for all YouTube Player Event listeners. * @typedef {'onReady'|'onStateChange'|'onError'|'onPlaybackQualityChange'|'onPlaybackRateChange'|'onApiChange'|'onAutoplayBlocked'} EventNames */ /** * Options specifically used when queuing or loading a playlist. * @typedef {Object} YTPlaylistOptions * @property {'playlist'|'user_uploads'} [listType='playlist'] - Specifies whether to use a standard playlist or user uploads feed. * @property {string|string[]} list - The ID of the target playlist or an array containing multiple video IDs. * @property {number} [index=0] - The zero-based index of the first video that should be played from the list. * @property {number} [startSeconds] - The specific time in seconds where the playback of the first video should begin. */ /** * Options used to cue or load a video based on its full media URL. * @typedef {Object} VideoByUrlOptions * @property {string} mediaContentUrl - The complete URL pointing to the desired YouTube video resource. * @property {number} [startSeconds] - Optional time in seconds to begin playback from within the video. * @property {number} [endSeconds] - Optional time in seconds when playback should stop within the video. */ /** * Options used to cue or load a video based on its unique ID. * @typedef {Object} VideoByIdOptions * @property {string} videoId - The unique identifier of the target YouTube video. * @property {number} [startSeconds] - Optional time in seconds to begin playback from within the video. * @property {number} [endSeconds] - Optional time in seconds when playback should stop within the video. */ /** * Detailed data object representing the current status and metadata of a loaded YouTube video. * @typedef {Object} VideoData * @property {boolean|null} allowLiveDvr - Whether DVR capabilities are permitted for live content. * @property {string|null} author - The name or ID of the video creator. * @property {boolean|null} backgroundable - Indicates if the video can be played in the background while minimized. * @property {string|null} cpn - Content Protection Network identifier. * @property {number|null} errorCode - A specific error code if playback failed. * @property {string|null} eventId - An ID related to a specific content event. * @property {boolean|null} hasProgressBarBoundaries - Flag indicating if the progress bar has defined start/end boundaries. * @property {boolean|null} isListed - Indicates if the video belongs to a list or series. * @property {boolean|null} isLive - True if the content is currently streaming live. * @property {boolean|null} isManifestless - Flag indicating if manifest files are not being used for streaming. * @property {boolean|null} isMultiChannelAudio - Indicates support for multiple audio channels. * @property {boolean|null} isPlayable - Overall flag indicating the video can be played by the player. * @property {boolean|null} isPremiere - True if the content is a scheduled premiere. * @property {boolean|null} isSeekable - Whether random access seeking within the video is allowed. * @property {boolean|null} isWindowedLive - Indicates if it is a windowed live event. * @property {string|null} itct - Indicator of Interactivity Content Tracking tag. * @property {number|null} paidContentOverlayDurationMs - Duration in milliseconds for paid content overlays. * @property {string|null} playerResponseCpn - Content Protection Network response identifier from the player itself. * @property {number|null} progressBarEndPositionUtcTimeMillis - UTC time in milliseconds for the end of the video's progress bar. * @property {number|null} progressBarStartPositionUtcTimeMillis - UTC time in milliseconds for the start of the video's progress bar. * @property {string|null} title - The descriptive title of the video. * @property {string|null} video_id - The unique ID string of the video content. */ /** * The main YouTube Player class instance. Manages all player interactions and state. */ declare class YouTubePlayer { /** * Constructor for the YouTube Player. Initializes the player element. * @param {string|HTMLElement} element - The DOM element or its ID where the player iframe will be inserted. * @param {YTPlayerOptions} [options] - Optional configuration settings for the player initialization. */ constructor(element: string | HTMLElement, options?: YTPlayerOptions); /** * Stores and retrieves the title of the currently loaded video. * @type {string|null|undefined} */ videoTitle: string | null | undefined; /** * Retrieves a comprehensive snapshot of the current video metadata and status (e.g., ID, author, playability). * @returns {Partial} A partial object containing various details about the loaded content. */ getVideoData(): Partial; /** * Plays the loaded/selected video. * * The final player state after this function executes will be playing (1). * @returns {void} */ playVideo(): void; /** * Pauses the playing video. * * The final player state after this function executes will be paused (2) * unless the player is in the ended (0) state when the function is called, * in which case the player state will not change. * @returns {void} */ pauseVideo(): void; /** * Stops and cancels the current video playback. * * Important: Unlike the pauseVideo function, which leaves the player in the * paused (2) state, the stopVideo function could put the player into any * not-playing state, including ended (0), paused (2), video cued (5) or * unstarted (-1). * @returns {void} */ stopVideo(): void; /** * Seeks to a specific time in the video. * @param {number} seconds - The time to seek to. * @param {boolean} [allowSeekAhead] - Whether to make a new request to the server if the time is outside the buffer. * @returns {void} */ seekTo(seconds: number, allowSeekAhead?: boolean): void; /** * Retrieves the current spherical properties for 360° video playback. * @returns {YTSphericalProperties} */ getSphericalProperties(): YTSphericalProperties; /** * Sets the orientation for 360° video playback. * @param {YTSphericalProperties & { enableOrientationSensor?: boolean }} properties - The new orientation properties. * @returns {void} */ setSphericalProperties(properties: YTSphericalProperties & { enableOrientationSensor?: boolean; }): void; /** * Loads and plays the next video in the playlist. * @returns {void} */ nextVideo(): void; /** * Loads and plays the previous video in the playlist. * @returns {void} */ previousVideo(): void; /** * Loads and plays the video at the specified index in the playlist. * @param {number} index - The zero-based index of the video. * @returns {void} */ playVideoAt(index: number): void; /** * Mutes the player. * @returns {void} */ mute(): void; /** * Unmutes the player. * @returns {void} */ unMute(): void; /** * Checks if the player is muted. * @returns {boolean} */ isMuted(): boolean; /** * Sets the player volume. * @param {number} volume - Volume level between 0 and 100. * @returns {void} */ setVolume(volume: number): void; /** * Gets the current player volume between 0 and 100. * @returns {number} */ getVolume(): number; /** * Sets the size of the