forked from shaka-project/shaka-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
219 lines (174 loc) · 6.27 KB
/
main.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
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
/**
* @license
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @suppress {duplicate} */
var shakaDemo = shakaDemo || {};
/** @private {shaka.cast.CastProxy} */
shakaDemo.castProxy_ = null;
/** @private {HTMLMediaElement} */
shakaDemo.video_ = null;
/** @private {shaka.Player} */
shakaDemo.player_ = null;
/** @private {shaka.Player} */
shakaDemo.localPlayer_ = null;
/** @private {shakaExtern.SupportType} */
shakaDemo.support_;
/** @private {ShakaControls} */
shakaDemo.controls_ = null;
/**
* The registered ID of the v2 Chromecast receiver demo.
* @const {string}
* @private
*/
shakaDemo.CC_APP_ID_ = '4E839F3A';
/**
* Initialize the application.
*/
shakaDemo.init = function() {
document.getElementById('errorDisplayCloseButton').addEventListener(
'click', shakaDemo.closeError);
// Display the version number.
document.getElementById('version').textContent = shaka.Player.version;
// Fill in the language preferences based on browser config, if available.
var language = navigator.language || 'en-us';
document.getElementById('preferredAudioLanguage').value = language;
document.getElementById('preferredTextLanguage').value = language;
// Read URL parameters.
var fields = location.search.split('?').slice(1).join('?');
fields = fields ? fields.split(';') : [];
var params = {};
for (var i = 0; i < fields.length; ++i) {
var kv = fields[i].split('=');
params[kv[0]] = kv.slice(1).join('=');
}
if ('lang' in params) {
document.getElementById('preferredAudioLanguage').value = params['lang'];
document.getElementById('preferredTextLanguage').value = params['lang'];
}
if ('asset' in params) {
document.getElementById('manifestInput').value = params['asset'];
}
if ('license' in params) {
document.getElementById('licenseServerInput').value = params['license'];
}
if ('logtoscreen' in params) {
document.getElementById('logToScreen').checked = true;
}
if ('noinput' in params) {
// Both the content container and body need different styles in this mode.
document.getElementById('container').className = 'noinput';
document.body.className = 'noinput';
}
if ('vv' in params && shaka.log) {
shaka.log.setLevel(shaka.log.Level.V2);
} else if ('v' in params && shaka.log) {
shaka.log.setLevel(shaka.log.Level.V1);
} else if ('debug' in params && shaka.log) {
shaka.log.setLevel(shaka.log.Level.DEBUG);
}
shakaDemo.setupLogging_();
shaka.polyfill.installAll();
if (!shaka.Player.isBrowserSupported()) {
var errorDisplayText = document.getElementById('errorDisplayText');
var error = 'Your browser is not supported!';
// IE8 and other very old browsers don't have textContent.
if (errorDisplayText.textContent === undefined) {
errorDisplayText.innerText = error;
} else {
errorDisplayText.textContent = error;
}
// Disable the load button.
var loadButton = document.getElementById('loadButton');
loadButton.disabled = true;
// Hide the error message's close button.
var errorDisplayCloseButton =
document.getElementById('errorDisplayCloseButton');
errorDisplayCloseButton.style.display = 'none';
// Make sure the error is seen.
errorDisplayText.style.fontSize = '250%';
var errorDisplay = document.getElementById('errorDisplay');
errorDisplay.style.display = 'block';
} else {
shaka.Player.probeSupport().then(function(support) {
shakaDemo.support_ = support;
var localVideo =
/** @type {!HTMLVideoElement} */(document.getElementById('video'));
var localPlayer = new shaka.Player(localVideo);
shakaDemo.castProxy_ = new shaka.cast.CastProxy(
localVideo, localPlayer, shakaDemo.CC_APP_ID_);
shakaDemo.video_ = shakaDemo.castProxy_.getVideo();
shakaDemo.player_ = shakaDemo.castProxy_.getPlayer();
shakaDemo.player_.addEventListener('error', shakaDemo.onErrorEvent_);
shakaDemo.localPlayer_ = localPlayer;
shakaDemo.setupAssets_();
shakaDemo.setupOffline_();
shakaDemo.setupConfiguration_();
shakaDemo.setupInfo_();
shakaDemo.controls_ = new ShakaControls();
shakaDemo.controls_.init(shakaDemo.castProxy_, shakaDemo.onError_,
shakaDemo.onCastStatusChange_);
// If a custom asset was given in the URL, select it now.
if ('asset' in params) {
var assetList = document.getElementById('assetList');
var customAsset = document.getElementById('customAsset');
assetList.selectedIndex = assetList.options.length - 1;
customAsset.style.display = 'block';
}
if ('play' in params) {
shakaDemo.load();
}
});
}
};
/**
* @param {!Event} event
* @private
*/
shakaDemo.onErrorEvent_ = function(event) {
var error = event.detail;
shakaDemo.onError_(error);
};
/**
* @param {!shaka.util.Error} error
* @private
*/
shakaDemo.onError_ = function(error) {
console.error('Player error', error);
var message = error.message || ('Error code ' + error.code);
document.getElementById('errorDisplay').style.display = 'block';
document.getElementById('errorDisplayText').textContent = message;
};
/**
* Closes the error bar.
*/
shakaDemo.closeError = function() {
document.getElementById('errorDisplay').style.display = 'none';
document.getElementById('errorDisplayText').textContent = '';
};
// IE 9 fires DOMContentLoaded, and enters the "interactive"
// readyState, before document.body has been initialized, so wait
// for window.load.
if (document.readyState == 'loading' ||
document.readyState == 'interactive') {
if (window.attachEvent) {
// IE8
window.attachEvent('onload', shakaDemo.init);
} else {
window.addEventListener('load', shakaDemo.init);
}
} else {
shakaDemo.init();
}