-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathplay_button.js
133 lines (110 loc) · 3.02 KB
/
play_button.js
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
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.provide('shaka.ui.PlayButton');
goog.require('shaka.ads.Utils');
goog.require('shaka.ui.Element');
goog.require('shaka.ui.Localization');
goog.require('shaka.util.Dom');
goog.requireType('shaka.ui.Controls');
/**
* @extends {shaka.ui.Element}
* @implements {shaka.extern.IUIPlayButton}
* @export
*/
shaka.ui.PlayButton = class extends shaka.ui.Element {
/**
* @param {!HTMLElement} parent
* @param {!shaka.ui.Controls} controls
*/
constructor(parent, controls) {
super(parent, controls);
/** @protected {!HTMLButtonElement} */
this.button = shaka.util.Dom.createButton();
this.parent.appendChild(this.button);
const LOCALE_UPDATED = shaka.ui.Localization.LOCALE_UPDATED;
this.eventManager.listen(this.localization, LOCALE_UPDATED, () => {
this.updateAriaLabel();
});
const LOCALE_CHANGED = shaka.ui.Localization.LOCALE_CHANGED;
this.eventManager.listen(this.localization, LOCALE_CHANGED, () => {
this.updateAriaLabel();
});
this.eventManager.listen(this.video, 'play', () => {
this.updateAriaLabel();
this.updateIcon();
});
this.eventManager.listen(this.video, 'pause', () => {
this.updateAriaLabel();
this.updateIcon();
});
this.eventManager.listen(this.video, 'seeking', () => {
this.updateAriaLabel();
this.updateIcon();
});
this.eventManager.listen(this.adManager, shaka.ads.Utils.AD_PAUSED, () => {
this.updateAriaLabel();
this.updateIcon();
});
this.eventManager.listen(this.adManager, shaka.ads.Utils.AD_RESUMED, () => {
this.updateAriaLabel();
this.updateIcon();
});
this.eventManager.listen(this.adManager, shaka.ads.Utils.AD_STARTED, () => {
this.updateAriaLabel();
this.updateIcon();
});
this.eventManager.listen(this.adManager, shaka.ads.Utils.AD_STOPPED, () => {
this.updateAriaLabel();
this.updateIcon();
});
this.eventManager.listen(this.button, 'click', () => {
if (this.ad) {
this.controls.playPauseAd();
if (this.ad.isLinear()) {
return;
}
}
this.controls.playPausePresentation();
});
if (this.ad) {
// There was already an ad.
this.updateAriaLabel();
this.updateIcon();
}
}
/**
* @return {boolean}
* @protected
* @override
*/
isPaused() {
if (this.ad && this.ad.isLinear()) {
return this.ad.isPaused();
}
return this.controls.presentationIsPaused();
}
/**
* @return {boolean}
* @protected
* @override
*/
isEnded() {
if (this.ad && this.ad.isLinear()) {
return false;
}
return this.player ? this.player.isEnded() : true;
}
/**
* Called when the button's aria label needs to change.
* To be overridden by subclasses.
*/
updateAriaLabel() {}
/**
* Called when the button's icon needs to change.
* To be overridden by subclasses.
*/
updateIcon() {}
};