-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
645 lines (579 loc) · 27.6 KB
/
index.html
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
<!--
Copyright (C) 2014 Google Inc. All Rights Reserved.
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.
-->
<!DOCTYPE html>
<html>
<head>
<title>Sample Media Receiver</title>
<!--
Cast APIs
-->
<script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
<!--
Cast Media Library
-->
<script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/mediaplayer/0.7.0/media_player.js"></script>
<style>
body {
overflow:hidden;
}
video {
height:auto;
width:100%;
text-align: center;
border:0px solid silver;
display: table-cell;
vertical-align: middle;
color: #FFFFFF;
background-color: #000000;
font-weight: bold;
font-family: Verdana, Geneva, sans-serif;
font-size:40px;
float:left;
z-index: 1;
position:absolute;
}
#messages {
color: #FFFFFF;
float: left;
margin-left: 25px;
margin-top: 25px;
z-index: 2;
position:absolute;
font-weight: bold;
width:1000PX;
background-color: rgba(0,0,0,0.5);
}
#messages span {
font-weight: normal;
}
</style>
</head>
<body>
<div id="messages">
<div id="title">Sample Media Receiver HUD</div>
<div>Application State: <span id="applicationState">-</span></div>
<div>Session Count: <span id="sessionCount">0</span></div>
<div>Media Element State: <span id="mediaElementState">-</span></div>
<div>Cast Receiver Manager Message: <span id="castReceiverManagerMessage">-</span></div>
<div>Media Manager Message: <span id="mediaManagerMessage">-</span></div>
<div>Message Bus Message: <span id="messageBusMessage">-</span></div>
<div>Volume: <span id="volumeMessage">Unknown</span></div>
<div>Host State: <span id="mediaHostState">Unknown</span></div>
<div>Media Type: <span id="mediaType">Unkown</span></div>
<div>Media Protocol: <span id="mediaProtocol">Unknown</span></div>
</div>
<video id="receiverVideoElement"></video>
<script type="text/javascript">
"use strict";
window.castReceiverManager = null;
window.mediaManager = null;
window.messageBus = null;
window.mediaElement = null;
window.mediaHost = null;
window.mediaProtocol = null;
window.mediaPlayer = null;
window.connectedCastSenders = []; // {senderId:'', channel:obj}
function setHudMessage(elementId, message) {
document.getElementById(elementId).innerHTML = '' + JSON.stringify(message);
}
// Initialize the receiver SDK before starting the app-specific logic
window.mediaElement = document.getElementById('receiverVideoElement');
window.mediaElement.autoplay = true;
console.log('### Application Loaded. Starting system.');
setHudMessage('applicationState','Loaded. Starting up.');
/**
* Sets the log verbosity level.
*
* Debug logging (all messages).
* DEBUG
*
* Verbose logging (sender messages).
* VERBOSE
*
* Info logging (events, general logs).
* INFO
*
* Error logging (errors).
* ERROR
*
* No logging.
* NONE
**/
cast.receiver.logger.setLevelValue(cast.receiver.LoggerLevel.DEBUG);
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
/**
* Called to process 'ready' event. Only called after calling castReceiverManager.start(config) and the
* system becomes ready to start receiving messages.
*
* @param {cast.receiver.CastReceiverManager.Event} event - can be null
*
* There is no default handler
*/
window.castReceiverManager.onReady = function(event) {
console.log("### Cast Receiver Manager is READY: " + JSON.stringify(event));
setHudMessage('castReceiverManagerMessage', 'READY: ' + JSON.stringify(event));
setHudMessage('applicationState','Loaded. Started. Ready.');
}
/**
* If provided, it processes the 'senderconnected' event.
* Called to process the 'senderconnected' event.
* @param {cast.receiver.CastReceiverManager.Event} event - can be null
*
* There is no default handler
*/
window.castReceiverManager.onSenderConnected = function(event) {
console.log("### Cast Receiver Manager - Sender Connected : " + JSON.stringify(event));
setHudMessage('castReceiverManagerMessage', 'Sender Connected: ' + JSON.stringify(event));
// TODO - add sender and grab CastChannel from CastMessageBus.getCastChannel(senderId)
var senders = window.castReceiverManager.getSenders();
setHudMessage('sessionCount', '' + senders.length);
}
/**
* If provided, it processes the 'senderdisconnected' event.
* Called to process the 'senderdisconnected' event.
* @param {cast.receiver.CastReceiverManager.Event} event - can be null
*
* There is no default handler
*/
window.castReceiverManager.onSenderDisconnected = function(event) {
console.log("### Cast Receiver Manager - Sender Disconnected : " + JSON.stringify(event));
setHudMessage('castReceiverManagerMessage', 'Sender Disconnected: ' + JSON.stringify(event));
var senders = window.castReceiverManager.getSenders();
setHudMessage('sessionCount', '' + senders.length);
//If last sender explicity disconnects, turn off
if(senders.length == 0 && event.reason == cast.receiver.system.DisconnectReason.REQUESTED_BY_SENDER)
window.close();
}
/**
* If provided, it processes the 'systemvolumechanged' event.
* Called to process the 'systemvolumechanged' event.
* @param {cast.receiver.CastReceiverManager.Event} event - can be null
*
* There is no default handler
*/
window.castReceiverManager.onSystemVolumeChanged = function(event) {
console.log("### Cast Receiver Manager - System Volume Changed : " + JSON.stringify(event));
setHudMessage('castReceiverManagerMessage', 'System Volume Changed: ' + JSON.stringify(event));
// See cast.receiver.media.Volume
console.log("### Volume: " + event.data['level'] + " is muted? " + event.data['muted']);
setHudMessage('volumeMessage', 'Level: ' + event.data['level'] + ' -- muted? ' + event.data['muted']);
}
/**
* Called to process the 'visibilitychanged' event.
*
* Fired when the visibility of the application has changed (for example
* after a HDMI Input change or when the TV is turned off/on and the cast
* device is externally powered). Note that this API has the same effect as
* the webkitvisibilitychange event raised by your document, we provided it
* as CastReceiverManager API for convenience and to avoid a dependency on a
* webkit-prefixed event.
*
* @param {cast.receiver.CastReceiverManager.Event} event - can be null
*
* There is no default handler for this event type.
*/
window.castReceiverManager.onVisibilityChanged = function(event) {
console.log("### Cast Receiver Manager - Visibility Changed : " + JSON.stringify(event));
setHudMessage('castReceiverManagerMessage', 'Visibility Changed: ' + JSON.stringify(event));
/** check if visible and pause media if not - add a timer to tear down after a period of time
if visibilty does not change back **/
if (event.data) { // It is visible
window.mediaElement.play(); // Resume media playback
window.clearTimeout(window.timeout); // Turn off the timeout
window.timeout = null;
} else {
window.mediaElement.pause(); // Pause playback
window.timeout = window.setTimeout(function(){window.close();}, 10000); // 10 Minute timeout
}
}
/**
* Use the messageBus to listen for incoming messages on a virtual channel using a namespace string.
* Also use messageBus to send messages back to a sender or broadcast a message to all senders.
* You can check the cast.receiver.CastMessageBus.MessageType that a message bus processes though a call
* to getMessageType. As well, you get the namespace of a message bus by calling getNamespace()
*/
window.messageBus = window.castReceiverManager.getCastMessageBus('urn:x-cast:com.google.devrel.custom');
/**
* The namespace urn:x-cast:com.google.devrel.custom is used to identify the protocol of showing/hiding
* the heads up display messages (The messages defined at the beginning of the html).
*
* The protocol consists of one string message: show
* In the case of the message value not being show - the assumed value is hide.
**/
window.messageBus.onMessage = function(event) {
console.log("### Message Bus - Media Message: " + JSON.stringify(event));
setHudMessage('messageBusMessage', event);
console.log("### CUSTOM MESSAGE: " + JSON.stringify(event));
// show/hide messages
console.log(event['data']);
if(event['data']==='show') {
document.getElementById('messages').style.display = 'block';
} else {
document.getElementById('messages').style.display = 'none';
}
}
// This class is used to send/receive media messages/events using the media protocol/namesapce (urn:x-cast:com.google.cast.media).
window.mediaManager = new cast.receiver.MediaManager(window.mediaElement);
/**
* Called when the media ends.
*
* mediaManager.resetMediaElement(cast.receiver.media.IdleReason.FINISHED);
**/
window.mediaManager['onEndedOrig'] = window.mediaManager.onEnded;
/**
* Called when the media ends
*/
window.mediaManager.onEnded = function() {
console.log("### Media Manager - ENDED" );
setHudMessage('mediaManagerMessage', 'ENDED');
window.mediaManager['onEndedOrig']();
}
/**
* Default implementation of onError.
*
* mediaManager.resetMediaElement(cast.receiver.media.IdleReason.ERROR)
**/
window.mediaManager['onErrorOrig'] = window.mediaManager.onError;
/**
* Called when there is an error not triggered by a LOAD request
* @param obj
*/
window.mediaManager.onError = function(obj) {
console.log("### Media Manager - error: " + JSON.stringify(obj));
setHudMessage('mediaManagerMessage', 'ERROR - ' + JSON.stringify(obj));
window.mediaManager['onErrorOrig'](obj);
}
/**
* Processes the get status event.
*
* Sends a media status message to the requesting sender (event.data.requestId)
**/
window.mediaManager['onGetStatusOrig'] = window.mediaManager.onGetStatus;
/**
* Processes the get status event.
* @param event
*/
window.mediaManager.onGetStatus = function(event) {
console.log("### Media Manager - GET STATUS: " + JSON.stringify(event));
setHudMessage('mediaManagerMessage', 'GET STATUS ' + JSON.stringify(event));
window.mediaManager['onGetStatusOrig'](event);
}
/**
* Default implementation of onLoadMetadataError.
*
* mediaManager.resetMediaElement(cast.receiver.media.IdleReason.ERROR, false);
* mediaManager.sendLoadError(cast.receiver.media.ErrorType.LOAD_FAILED);
**/
window.mediaManager['onLoadMetadataErrorOrig'] = window.mediaManager.onLoadMetadataError;
/**
* Called when load has had an error, overridden to handle application specific logic.
* @param event
*/
window.mediaManager.onLoadMetadataError = function(event) {
console.log("### Media Manager - LOAD METADATA ERROR: " + JSON.stringify(event));
setHudMessage('mediaManagerMessage', 'LOAD METADATA ERROR: ' + JSON.stringify(event));
window.mediaManager['onLoadMetadataErrorOrig'](event);
}
/**
* Default implementation of onMetadataLoaded
*
* Passed a cast.receiver.MediaManager.LoadInfo event object
* Sets the mediaElement.currentTime = loadInfo.message.currentTime
* Sends the new status after a LOAD message has been completed succesfully.
* Note: Applications do not normally need to call this API.
* When the application overrides onLoad, it may need to manually declare that
* the LOAD request was sucessful. The default implementaion will send the new
* status to the sender when the video/audio element raises the
* 'loadedmetadata' event.
* The default behavior may not be acceptable in a couple scenarios:
*
* 1) When the application does not want to declare LOAD succesful until for
* example 'canPlay' is raised (instead of 'loadedmetadata').
* 2) When the application is not actually loading the media element (for
* example if LOAD is used to load an image).
**/
window.mediaManager['onLoadMetadataOrig'] = window.mediaManager.onLoadMetadataLoaded;
/**
* Called when load has completed, overridden to handle application specific logic.
* @param event
*/
window.mediaManager.onLoadMetadataLoaded = function(event) {
console.log("### Media Manager - LOADED METADATA: " + JSON.stringify(event));
setHudMessage('mediaManagerMessage', 'LOADED METADATA: ' + JSON.stringify(event));
window.mediaManager['onLoadMetadataOrig'](event);
}
/**
* Processes the pause event.
*
* mediaElement.pause();
* Broadcast (without sending media information) to all senders that pause has happened.
**/
window.mediaManager['onPauseOrig'] = window.mediaManager.onPause;
/**
* Process pause event
* @param event
*/
window.mediaManager.onPause = function(event) {
console.log("### Media Manager - PAUSE: " + JSON.stringify(event));
setHudMessage('mediaManagerMessage', 'PAUSE: ' + JSON.stringify(event));
window.mediaManager['onPauseOrig'](event);
}
/**
* Default - Processes the play event.
*
* mediaElement.play();
*
**/
window.mediaManager['onPlayOrig'] = window.mediaManager.onPlay;
/**
* Process play event
* @param event
*/
window.mediaManager.onPlay = function(event) {
console.log("### Media Manager - PLAY: " + JSON.stringify(event));
setHudMessage('mediaManagerMessage', 'PLAY: ' + JSON.stringify(event));
window.mediaManager['onPlayOrig'](event);
}
/**
* Default implementation of the seek event.
* Sets the mediaElement.currentTime to event.data.currentTime.
* If the event.data.resumeState is cast.receiver.media.SeekResumeState.PLAYBACK_START and the mediaElement is paused then
* call mediaElement.play(). Otherwise if event.data.resumeState is cast.receiver.media.SeekResumeState.PLAYBACK_PAUSE and
* the mediaElement is not paused, call mediaElement.pause().
* Broadcast (without sending media information) to all senders that seek has happened.
**/
window.mediaManager['onSeekOrig'] = window.mediaManager.onSeek;
/**
* Process seek event
* @param event
*/
window.mediaManager.onSeek = function(event) {
console.log("### Media Manager - SEEK: " + JSON.stringify(event));
setHudMessage('mediaManagerMessage', 'SEEK: ' + JSON.stringify(event));
window.mediaManager['onSeekOrig'](event);
}
/**
* Default implementation of the set volume event.
* Checks event.data.volume.level is defined and sets the mediaElement.volume to the value
* Checks event.data.volume.muted is defined and sets the mediaElement.muted to the value
* Broadcasts (without sending media information) to all senders that the volume has changed.
**/
window.mediaManager['onSetVolumeOrig'] = window.mediaManager.onSetVolume;
/**
* Process set volume event
* @param event
*/
window.mediaManager.onSetVolume = function(event) {
console.log("### Media Manager - SET VOLUME: " + JSON.stringify(event));
setHudMessage('mediaManagerMessage', 'SET VOLUME: ' + JSON.stringify(event));
window.mediaManager['onSetVolumeOrig'](event);
}
/**
* Processes the stop event.
*
* window.mediaManager.resetMediaElement(cast.receiver.media.IdleReason.CANCELLED, true, event.data.requestId);
*
* Resets Media Element to IDLE state. After this call the mediaElement
* properties will change, paused will be true, currentTime will be zero and
* the src attribute will be empty. This only needs to be manually called if the
* developer wants to override the default behavior of onError, onStop or
* onEnded, for example.
**/
window.mediaManager['onStopOrig'] = window.mediaManager.onStop;
/**
* Process stop event
* @param event
*/
window.mediaManager.onStop = function(event) {
console.log("### Media Manager - STOP: " + JSON.stringify(event));
setHudMessage('mediaManagerMessage', 'STOP: ' + JSON.stringify(event));
window.mediaManager['onStopOrig'](event);
}
/**
* Default implementation for the load event.
*
* Sets the mediaElement.autoplay to false.
* Checks that data.media and data.media.contentId are valid then sets the mediaElement.src to the
* data.media.contentId.
*
* Checks the data.autoplay value:
* - if undefined sets mediaElement.autoplay = true
* - if has value then sets mediaElement.autoplay to that value
**/
window.mediaManager['onLoadOrig'] = window.mediaManager.onLoad;
/**
* Processes the load event.
* @param event
*/
window.mediaManager.onLoad = function(event) {
console.log("### Media Manager - LOAD: " + JSON.stringify(event));
setHudMessage('mediaManagerMessage', 'LOAD ' + JSON.stringify(event));
// TODO - setup for load here
// TODO - if there is an error during load: call mediaManager.sendLoadError to notify sender
// TODO - if there is no error call mediaManager.sendLoadCompleteComplete
// TODO - call mediaManager.setMediaInformation(MediaInformation)
if(window.mediaPlayer !== null) {
window.mediaPlayer.unload(); // Ensure unload before loading again
}
if (event.data['media'] && event.data['media']['contentId']) {
var url = event.data['media']['contentId'];
window.mediaHost = new cast.player.api.Host({
'mediaElement': window.mediaElement,
'url': url
});
window.mediaHost.onError = function (errorCode) {
console.error('### HOST ERROR - Fatal Error: code = ' + errorCode);
setHudMessage('mediaHostState', 'Fatal Error: code = ' + errorCode);
if (window.mediaPlayer !== null) {
window.mediaPlayer.unload();
}
}
var initialTimeIndexSeconds = event.data['media']['currentTime'] || 0;
// TODO: real code would know what content it was going to access and this would not be here.
var protocol = null;
var parser = document.createElement('a');
parser.href = url;
var ext = ext = parser.pathname.split('.').pop();
if (ext === 'm3u8') {
protocol = cast.player.api.CreateHlsStreamingProtocol(window.mediaHost);
} else if (ext === 'mpd') {
protocol = cast.player.api.CreateDashStreamingProtocol(window.mediaHost);
} else if (ext === 'ism/') {
protocol = cast.player.api.CreateSmoothStreamingProtocol(window.mediaHost);
}
console.log('### Media Protocol Identified as ' + ext);
setHudMessage('mediaProtocol', ext);
if (protocol === null) {
// Call on original handler
window.mediaManager['onLoadOrig'](event); // Call on the original callback
} else {
// Advanced Playback - HLS, MPEG DASH, SMOOTH STREAMING
// Player registers to listen to the media element events through the mediaHost property of the
// mediaElement
window.mediaPlayer = new cast.player.api.Player(window.mediaHost);
window.mediaPlayer.load(protocol, initialTimeIndexSeconds);
}
}
}
/**
* Application config
**/
var appConfig = new cast.receiver.CastReceiverManager.Config();
/**
* Text that represents the application status. It should meet
* internationalization rules as may be displayed by the sender application.
* @type {string|undefined}
**/
appConfig.statusText = 'Ready to play';
/**
* Maximum time in seconds before closing an idle
* sender connection. Setting this value enables a heartbeat message to keep
* the connection alive. Used to detect unresponsive senders faster than
* typical TCP timeouts. The minimum value is 5 seconds, there is no upper
* bound enforced but practically it's minutes before platform TCP timeouts
* come into play. Default value is 10 seconds.
* @type {number|undefined}
**/
appConfig.maxInactivity = 6000; // 10 minutes for testing, use default 10sec in prod by not setting this value
/**
* Initializes the system manager. The application should call this method when
* it is ready to start receiving messages, typically after registering
* to listen for the events it is interested on.
*/
window.castReceiverManager.start(appConfig);
/**
play - The process of play has started
waiting - When the video stops due to buffering
volumechange - volume has changed
stalled - trying to get data, but not available
ratechange - some speed changed
canplay - It is possible to start playback, but no guarantee of not buffering
canplaythrough - It seems likely that we can play w/o buffering issues
ended - the video has finished
error - error occured during loading of the video
playing - when the video has started playing
seeking - started seeking
seeked - seeking has completed
http://www.w3.org/2010/05/video/mediaevents.html for more info.
**/
window.mediaElement.addEventListener('loadstart', function(e){
console.log("######### MEDIA ELEMENT LOAD START");
setHudMessage('mediaElementState','Load Start');
});
window.mediaElement.addEventListener('loadeddata', function(e){
console.log("######### MEDIA ELEMENT DATA LOADED");
setHudMessage('mediaElementState','Data Loaded');
});
window.mediaElement.addEventListener('canplay', function(e){
console.log("######### MEDIA ELEMENT CAN PLAY");
setHudMessage('mediaElementState','Can Play');
});
window.mediaElement.addEventListener('ended', function(e){
console.log("######### MEDIA ELEMENT ENDED");
setHudMessage('mediaElementState','Ended');
});
window.mediaElement.addEventListener('playing', function(e){
console.log("######### MEDIA ELEMENT PLAYING");
setHudMessage('mediaElementState','Playing');
});
window.mediaElement.addEventListener('waiting', function(e){
console.log("######### MEDIA ELEMENT WAITING");
setHudMessage('mediaElementState','Waiting');
});
window.mediaElement.addEventListener('stalled', function(e){
console.log("######### MEDIA ELEMENT STALLED");
setHudMessage('mediaElementState','Stalled');
});
window.mediaElement.addEventListener('error', function(e){
console.log("######### MEDIA ELEMENT ERROR " + e);
setHudMessage('mediaElementState','Error');
});
window.mediaElement.addEventListener('abort', function(e){
console.log("######### MEDIA ELEMENT ABORT " + e);
setHudMessage('mediaElementState','Abort');
});
window.mediaElement.addEventListener('suspend', function(e){
console.log("######### MEDIA ELEMENT SUSPEND " + e);
setHudMessage('mediaElementState','Suspended');
});
window.mediaElement.addEventListener('progress', function(e){
setHudMessage('mediaElementState','Progress');
});
window.mediaElement.addEventListener('seeking', function(e){
console.log("######### MEDIA ELEMENT SEEKING " + e);
setHudMessage('mediaElementState','Seeking');
});
window.mediaElement.addEventListener('seeked', function(e){
console.log("######### MEDIA ELEMENT SEEKED " + e);
setHudMessage('mediaElementState','Seeked');
});
/**
* ALTERNATIVE TO onVisibilityChanged
*
* Use this to know when the user switched away from the Cast device input. It depends on the TV
* Supporting CEC
**/
document.addEventListener('webkitvisibilitychange', function(){
if(document.webkithidden) {
window.mediaElement.pause(); // Pause playback
window.timeout = window.setTimeout(function(){window.close();}, 10000); // 10 second timeout
} else {
window.mediaElement.play(); // Resume media playback
window.clearTimeout(window.timeout); // Turn off the timeout
window.timeout = null;
}
});
// Add your app logic here after the receiver SDK has been initialized.
</script>
</body>
</html>