forked from feross/yt-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
263 lines (253 loc) · 11.1 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// Type definitions for yt-player 3.4
// Project: https://github.com/feross/yt-player
// Definitions by: Thomas Röggla <https://github.com/troeggla>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { EventEmitter } from "eventemitter3";
interface YouTubePlayerOptions {
/** This parameter indicates the width of the player. */
width?: number;
/** This parameter indicates the height of the player. */
height?: number;
/**
* This parameter indicates whether the initial video will automatically
* start to play when the player loads. The default value is false.
*/
autoplay?: boolean;
/**
* This parameter indicates whether closed captions should be shown, even if
* the user has turned captions off. The default behavior is based on user
* preference.
*/
captions?: false | string;
/**
* This parameter indicates whether the video player controls are displayed.
* The default value is true.
*/
controls?: boolean;
/**
* This parameter indicates whether the player will respond to keyboard
* shortcuts. The default value is true.
*/
keyboard?: boolean;
/**
* This parameter indicates whether the player will show a fullscreen
* button. The default value is true.
*/
fullscreen?: boolean;
/**
* This parameter indicates whether the player will show video annotations.
* The default value is true.
*/
annotations?: boolean;
/**
* This parameter lets you use a YouTube player that does not show a
* YouTube logo. Even when this option is enabled, a small YouTube text
* label will still display in the upper-right corner of a paused video
* when the user's mouse pointer hovers over the player.
*/
modestBranding?: boolean;
/**
* This parameter indicates whether the player should show related videos
* from other channels
*/
related?: boolean;
/**
* The time between onTimeupdate callbacks, in milliseconds. Default is
* 1000.
*/
timeupdateFrequency?: number;
/**
* This parameter controls whether videos play inline or fullscreen in an
* HTML5 player on iOS. The default value is true.
*/
playsInline?: boolean;
}
interface YouTubePlayerListInfo {
listType?:string
list:string
index?:number
startSeconds?:number
suggestedQuality?:string
}
type YouTubePlayerState = "unstarted" | "ended" | "playing" | "paused" | "buffering" | "cued";
type YouTubePlayerQuality = "small" | "medium" | "large" | "hd720" | "hd1080" | "highres" | "default";
/**
* Simple, robust, blazing-fast YouTube Player API
*
* @see https://github.com/feross/yt-player
*/
declare class YouTubePlayer extends EventEmitter {
/** Returns the currently loaded video ID, i.e.what was passed to load(). */
videoId: string;
/** Returns true if destroy() has been called on the player. */
destroyed: boolean;
/**
* Create a new YouTube player. The player will take the place of the HTML
* element element. Alternatively, element can be a selector string, which
* will be passed to document.querySelector().
*
* Examples: `#player`, `.youtube-player`, or a DOM node.
*
* Optionally, provide an options object opts to customize the player.
*/
constructor(element: HTMLElement | string, options?: YouTubePlayerOptions);
/**
* This function loads the specified videoId. An example of a videoId is
* 'GKSRyLdjsPA'.
*
* Optionally, specify an autoplay parameter to indicate whether the video
* should begin playing immediately, or wait for a call to player.play().
* Default is false.
*
* This should be the first function called on a new Player instance.
*/
load(videoId: string, autoplay?: boolean): void;
loadList (listObj: YouTubePlayerListInfo, autoplay?:boolean): void
/** Plays the currently loaded video. */
play(): void;
/** Plays the video in the playlist. */
playVideoAt(index: number): void;
/** Pauses the currently loaded video. */
pause(): void;
/**
* Stops and cancels loading of the current video.This function should be
* reserved for rare situations when you know that the user will not be
* watching additional video in the player.If your intent is to pause the
* video, you should just call pause().If you want to change the video that
* the player is playing, you can call load() without calling stop() first.
*/
stop(): void;
/**
* Seeks to a specified time in the video.If the player is paused when the
* function is called, it will remain paused.If the function is called from
* another state(playing, video cued, etc.), the player will play the
* video.The player will advance to the closest keyframe before that time
* unless the player has already downloaded the portion of the video to
* which the user is seeking.
*/
seek(seconds: number): void;
/** Sets the volume.Accepts an integer between 0 and 100. */
setVolume(volume: number): void;
/** Returns the player's current volume, an integer between 0 and 100. Note that getVolume() will return the volume even if the player is muted. */
getVolume(): number;
/** Mutes the player. */
mute(): void;
/** Unmutes the player. */
unMute(): void;
/** Returns true if the player is muted, false if not. */
isMuted(): boolean;
/** Sets the size in pixels of the <iframe> that contains the player. */
setSize(width: number, height: number): void;
/**
* This function sets the suggested playback rate for the current video.If
* the playback rate changes, it will only change for the video that is
* already being played.Calling load() will reset the playback rate to 1.
*/
setPlaybackRate(rate: number): void;
/**
* This function retrieves the playback rate of the currently playing
* video.The default playback rate is 1, which indicates that the video is
* playing at normal speed.Playback rates may include values like 0.25, 0.5,
* 1, 1.5, and 2.
*/
getPlaybackRate(): number;
/**
* The function returns an array of numbers ordered from slowest to fastest
* playback speed.Even if the player does not support variable playback
* speeds, the array should always contain at least one value(1).
*/
getAvailablePlaybackRates(): number[];
/**
* This function sets the suggested video quality for the current video.
* The function causes the video to reload at its current position in the
* new quality. If the playback quality does change, it will only change
* for the video being played. Calling this function does not guarantee
* that the playback quality will actually change. However, if the playback
* quality does change, the 'playbackqualitychange' event will fire, and
* your code should respond to the event rather than the fact that it
* called the setPlaybackQuality function.
*
* The suggestedQuality parameter value can be 'small', 'medium', 'large',
* 'hd720', 'hd1080', 'highres' or 'default'. We recommend that you set the
* parameter value to 'default', which instructs YouTube to select the most
* appropriate playback quality, which will vary for different users,
* videos, systems and other playback conditions.
*
* If you call the setPlaybackQuality function with a suggestedQuality
* level that is not available for the video, then the quality will be set
* to the next lowest level that is available. In addition, setting
* suggestedQuality to a value that is not a recognized quality level is
* equivalent to setting suggestedQuality to 'default'.
*/
setPlaybackQuality(suggestedQuality: YouTubePlayerQuality): void;
/**
* Returns the duration in seconds of the currently playing video.Note that
* getDuration() will return 0 until the video's metadata is loaded, which
* normally happens just before the video starts playing.
*/
getDuration(): number;
/**
* Returns a number between 0 and 1 that specifies the percentage of the
* video that the player shows as buffered.
*/
getProgress(): number;
/**
* Returns the state of the player.Possible values are: 'unstarted',
* 'ended', 'playing', 'paused', 'buffering', or 'cued'.
*/
getState(): YouTubePlayerState;
/** Returns the elapsed time in seconds since the video started playing. */
getCurrentTime(): number;
/** Returns playlist. */
getPlaylist(): string[];
/** Returns current index in the playlist. */
getPlaylistIndex(): Number
/**
* Removes the <iframe> containing the player and cleans up all resources.
*/
destroy(): void;
/**
* This event fires when the time indicated by the getCurrentTime() method
* has been updated.
*/
on(event: 'timeupdate', callback: (seconds: number) => void): this;
/**
* This event fires whenever the video playback quality changes. Possible
* values are: 'small', 'medium', 'large', 'hd720', 'hd1080', 'highres'.
*/
on(event: 'playbackQualityChange', callback: (quality: YouTubePlayerQuality) => void): this;
/** This event fires whenever the video playback rate changes. */
on(event: 'playbackRateChange', callback: (playbackRate: number) => void): this;
/**
* These events fire when the player enters the respective state. These
* event names are the same as the possible return values from
* player.getState().
*
* When the player first loads a video, it will broadcast an unstarted
* event. When a video is cued and ready to play, the player will broadcast
* a cued event.
*/
on(event: YouTubePlayerState, callback: () => void): this;
/**
* This event fires if a fatal error occurs in the player. This does not
* include videos that fail to play, for whatever reason.
*/
on(event: 'error', callback: (err: Error) => void): this;
/**
* This event fires if the YouTube player cannot play the given video. This
* is not a fatal error. This event is reported separately from the 'error'
* event so there is an opportunity to play another video gracefully.
* Possible reasons for this error:
*
* - The video requested was not found. This error occurs when a video has
* been removed (for any reason) or has been marked as private.
* - The owner of the requested video does not allow it to be played in
* embedded players.
* - The request contains an invalid parameter value. For example, this
* error occurs if you specify a videoId that does not have 11 characters,
* or if the videoId contains invalid characters, such as exclamation
* points or asterisks.
*/
on(event: 'unplayable', callback: (videoId: string) => void): this;
}
export = YouTubePlayer;