forked from shaka-project/shaka-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay_button.js
103 lines (83 loc) · 2.42 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
/** @license
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.provide('shaka.ui.PlayButton');
goog.require('shaka.ui.Element');
goog.require('shaka.ui.Locales');
goog.require('shaka.ui.Localization');
goog.require('shaka.util.Dom');
/**
* @extends {shaka.ui.Element}
* @export
*/
shaka.ui.PlayButton = class extends shaka.ui.Element {
/**
* @param {!HTMLElement} parent
* @param {!shaka.ui.Controls} controls
*/
constructor(parent, controls) {
super(parent, controls);
const AdManager = shaka.ads.AdManager;
/** @protected {!HTMLElement} */
this.button = shaka.util.Dom.createHTMLElement('button');
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.adManager, AdManager.AD_PAUSED, () => {
this.updateAriaLabel();
this.updateIcon();
});
this.eventManager.listen(this.adManager, AdManager.AD_RESUMED, () => {
this.updateAriaLabel();
this.updateIcon();
});
this.eventManager.listen(this.adManager, AdManager.AD_STARTED, () => {
this.updateAriaLabel();
this.updateIcon();
});
this.eventManager.listen(this.button, 'click', () => {
if (this.ad) {
this.controls.playPauseAd();
} else {
this.controls.playPausePresentation();
}
});
}
/**
* @return {boolean}
* @protected
*/
isPaused() {
if (this.ad) {
return this.ad.isPaused();
}
return this.controls.presentationIsPaused();
}
/** @protected */
updateAriaLabel() {
const LocIds = shaka.ui.Locales.Ids;
const label = this.isPaused() ? LocIds.PLAY : LocIds.PAUSE;
this.button.setAttribute(shaka.ui.Constants.ARIA_LABEL,
this.localization.resolve(label));
}
/**
* Called when the button's icon needs to change.
* To be overridden by subclasses.
*/
updateIcon() {}
};