forked from openplayerjs/openplayerjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openplayer.d.ts
172 lines (164 loc) · 5.36 KB
/
openplayer.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
// Type definitions for OpenPlayer 1.3
// Project: https://github.com/openplayerjs/openplayerjs
// Definitions by: Rafael Miranda <https://github.com/rafa8626>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
declare namespace OpenPlayer {
interface PlayerComponent {
create(): void;
destroy(): void;
}
interface EventsList {
[key: string]: (e: any) => void;
}
interface Source {
src: string;
type: string;
drm?: object;
}
interface Track {
srclang: string;
src: string;
kind: string;
label: string;
default?: boolean;
}
class Media {
constructor(element: HTMLMediaElement);
canPlayType(mimeType: string): boolean;
load(): void;
play(): Promise<void>;
pause(): void;
destroy(): void;
// Setters/getters
src(media?: Source[]): Source[];
volume(value?: number): number;
muted(value?: boolean): boolean;
playbackRate(value?: number): number;
currentTime(value?: number): number;
duration(): number;
paused(): boolean;
ended(): boolean;
}
class Ads {
constructor(media: Media, adsUrl: string);
load(): void;
play(): void;
pause(): void;
destroy(): void;
resizeAds(width?: number, height?: number, transform?: string): void;
// Setters/getters
volume(value: number): number;
muted(value: boolean): boolean;
currentTime(value: number): number;
duration(): number;
paused(): boolean;
ended(): boolean;
}
/**
* This class handles the creation/destruction of all player's control elements.
*/
class Controls implements PlayerComponent {
constructor(player: Player);
create(): void;
destroy(): void;
getContainer(): HTMLDivElement;
}
/**
* This class generates controls to play native media (such as MP4, MP3, HLS, M(PEG-DASH),
* and have a unified look-and-feel on all modern browsers (including IE11)
*/
class Player {
/**
* Convert all the video/audio tags with `op-player` class in a OpenMedia player instance.
*/
static init(): void;
/**
* Create an instance of Player.
*/
constructor(element: HTMLMediaElement | string, adsUrl?: string, fill?: boolean);
/**
* Create all the markup and events needed for the player.
*
* Note that no controls will be created if user is trying to instantiate a video element
* in an iPhone, because iOS will only use QuickTime as a default constrain.
*/
init(): void;
/**
* Load media.
*
* HLS and M(PEG)-DASH perform more operations during loading if browser does not support them natively.
*/
load(): void;
/**
* Play media.
*
* If Ads are detected, different methods than the native ones are triggered with this operation.
*/
play(): void;
/**
* Pause media.
*
* If Ads are detected, different methods than the native ones are triggered with this operation.
*/
pause(): void;
/**
* Destroy OpenMedia Player instance (including all events associated) and return the
* video/audio tag to its original state.
*/
destroy(): void;
/**
* Retrieve the parent element (with `op-player` class) of the native video/audio tag.
*
* This element is mostly useful to attach other player component's markup in a place
* different than the controls bar.
*/
getContainer(): HTMLElement;
/**
* Retrieve an instance of the controls object used in the player instance.
*
* This element is mostly useful to attach other player component's markup in the controls bar.
*/
getControls(): Controls;
/**
* Retrieve the original video/audio tag.
*
* This element is useful to attach different events in other player's components.
*/
getElement(): HTMLMediaElement;
/**
* Retrieve the events attached to the player.
*
* This list does not include individual events associated with other player's components.
*/
getEvents(): EventsList;
/**
* Retrieve the current media object (could be Ads or any other media type).
*/
activeElement(): Ads | Media;
/**
* Check if current media is an instance of a native media type.
*/
isMedia(): boolean;
/**
* Check if current media is an instance of an Ad.
*/
isAd(): boolean;
/**
* Retrieve an instance of the `Media` object.
*/
getMedia(): Media;
/**
* Retrieve an instance of the `Ads` object.
*/
getAd(): Ads;
/**
* Append a new `<track>` tag to the video/audio tag and dispatch event
* so it gets registered/loaded in the player, via `controlschanged` event.
*/
addCaptions(args: Track): void;
// Setters/getters
src(media?: Source[]): Source[];
id(): string;
}
}