OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * @param {Element} playerContainer Main container. | 8 * @param {Element} playerContainer Main container. |
9 * @param {Element} videoContainer Container for the video element. | 9 * @param {Element} videoContainer Container for the video element. |
10 * @param {Element} controlsContainer Container for video controls. | 10 * @param {Element} controlsContainer Container for video controls. |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 function(results) { | 298 function(results) { |
299 var url = results[0]; | 299 var url = results[0]; |
300 var token = results[1]; | 300 var token = results[1]; |
301 document.querySelector('#thumbnail').style.backgroundImage = | 301 document.querySelector('#thumbnail').style.backgroundImage = |
302 'url(' + url + '&access_token=' + token + ')'; | 302 'url(' + url + '&access_token=' + token + ')'; |
303 }).catch(function() { | 303 }).catch(function() { |
304 // Shows no image on error. | 304 // Shows no image on error. |
305 document.querySelector('#thumbnail').style.backgroundImage = ''; | 305 document.querySelector('#thumbnail').style.backgroundImage = ''; |
306 }); | 306 }); |
307 | 307 |
308 var media = new MediaManager(video.entry); | |
hirono
2014/08/14 09:37:18
Is it OK to remove this line?
yoshiki
2014/08/14 10:17:43
This is a dup with L295.
| |
309 | |
310 var videoElementInitializePromise; | 308 var videoElementInitializePromise; |
311 if (this.currentCast_) { | 309 if (this.currentCast_) { |
312 videoPlayerElement.setAttribute('casting', true); | 310 videoPlayerElement.setAttribute('casting', true); |
313 | 311 |
314 document.querySelector('#cast-name-label').textContent = | 312 document.querySelector('#cast-name-label').textContent = |
315 loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON'); | 313 loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON'); |
316 document.querySelector('#cast-name').textContent = | 314 document.querySelector('#cast-name').textContent = |
317 this.currentCast_.friendlyName; | 315 this.currentCast_.friendlyName; |
318 | 316 |
317 videoPlayerElement.setAttribute('castable', true); | |
318 | |
319 videoElementInitializePromise = | 319 videoElementInitializePromise = |
320 media.isAvailableForCast().then(function(result) { | 320 media.isAvailableForCast().then(function(result) { |
321 if (!result) | 321 if (!result) |
322 return Promise.reject('No casts are available.'); | 322 return Promise.reject('No casts are available.'); |
323 | 323 |
324 return new Promise(function(fulfill, reject) { | 324 return new Promise(function(fulfill, reject) { |
325 chrome.cast.requestSession( | 325 chrome.cast.requestSession( |
326 fulfill, reject, undefined, this.currentCast_.label); | 326 fulfill, reject, undefined, this.currentCast_.label); |
327 }.bind(this)).then(function(session) { | 327 }.bind(this)).then(function(session) { |
328 this.currentSession_ = session; | 328 this.currentSession_ = session; |
329 this.videoElement_ = new CastVideoElement(media, session); | 329 this.videoElement_ = new CastVideoElement(media, session); |
330 this.controls.attachMedia(this.videoElement_); | 330 this.controls.attachMedia(this.videoElement_); |
331 }.bind(this)); | 331 }.bind(this)); |
332 }.bind(this)); | 332 }.bind(this)); |
333 } else { | 333 } else { |
334 videoPlayerElement.removeAttribute('casting'); | 334 videoPlayerElement.removeAttribute('casting'); |
335 | 335 |
336 this.videoElement_ = document.createElement('video'); | 336 this.videoElement_ = document.createElement('video'); |
337 document.querySelector('#video-container').appendChild( | 337 document.querySelector('#video-container').appendChild( |
338 this.videoElement_); | 338 this.videoElement_); |
339 | 339 |
340 this.controls.attachMedia(this.videoElement_); | 340 this.controls.attachMedia(this.videoElement_); |
341 this.videoElement_.src = video.url; | 341 this.videoElement_.src = video.url; |
342 | 342 |
343 media.isAvailableForCast().then(function(result) { | |
hirono
2014/08/14 09:37:18
Can we assign the return value to videoElementInit
yoshiki
2014/08/14 10:17:43
I don't think this block the initialization. It ju
hirono
2014/08/14 10:35:47
SGTM. So please add an error handler after then.
yoshiki
2014/08/14 10:52:13
Done.
| |
344 if (result) | |
345 videoPlayerElement.setAttribute('castable', true); | |
346 else | |
347 videoPlayerElement.removeAttribute('castable'); | |
348 }.bind(this)); | |
349 | |
343 videoElementInitializePromise = Promise.resolve(); | 350 videoElementInitializePromise = Promise.resolve(); |
344 } | 351 } |
345 | 352 |
346 videoElementInitializePromise. | 353 videoElementInitializePromise. |
347 then(function() { | 354 then(function() { |
348 var handler = function(currentPos) { | 355 var handler = function(currentPos) { |
349 if (currentPos === this.currentPos_) { | 356 if (currentPos === this.currentPos_) { |
350 if (opt_callback) | 357 if (opt_callback) |
351 opt_callback(); | 358 opt_callback(); |
352 videoPlayerElement.removeAttribute('loading'); | 359 videoPlayerElement.removeAttribute('loading'); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 this.currentCast_ = cast || null; | 493 this.currentCast_ = cast || null; |
487 this.updateCheckOnCastMenu_(); | 494 this.updateCheckOnCastMenu_(); |
488 this.reloadCurrentVideo(); | 495 this.reloadCurrentVideo(); |
489 }; | 496 }; |
490 | 497 |
491 /** | 498 /** |
492 * Set the list of casts. | 499 * Set the list of casts. |
493 * @param {Array.<Object>} casts List of casts. | 500 * @param {Array.<Object>} casts List of casts. |
494 */ | 501 */ |
495 VideoPlayer.prototype.setCastList = function(casts) { | 502 VideoPlayer.prototype.setCastList = function(casts) { |
496 var button = document.querySelector('.cast-button'); | 503 var videoPlayerElement = document.querySelector('#video-player'); |
497 var menu = document.querySelector('#cast-menu'); | 504 var menu = document.querySelector('#cast-menu'); |
498 menu.innerHTML = ''; | 505 menu.innerHTML = ''; |
499 | 506 |
500 // TODO(yoshiki): Handle the case that the current cast disappears. | 507 // TODO(yoshiki): Handle the case that the current cast disappears. |
501 | 508 |
502 if (casts.length === 0) { | 509 if (casts.length === 0) { |
503 button.classList.add('hidden'); | 510 videoPlayerElement.removeAttribute('cast-available'); |
504 if (this.currentCast_) | 511 if (this.currentCast_) |
505 this.onCurrentCastDisappear_(); | 512 this.onCurrentCastDisappear_(); |
506 return; | 513 return; |
507 } | 514 } |
508 | 515 |
509 if (this.currentCast_) { | 516 if (this.currentCast_) { |
510 var currentCastAvailable = casts.some(function(cast) { | 517 var currentCastAvailable = casts.some(function(cast) { |
511 return this.currentCast_.label === cast.label; | 518 return this.currentCast_.label === cast.label; |
512 }.wrap(this)); | 519 }.wrap(this)); |
513 | 520 |
514 if (!currentCastAvailable) | 521 if (!currentCastAvailable) |
515 this.onCurrentCastDisappear_(); | 522 this.onCurrentCastDisappear_(); |
516 } | 523 } |
517 | 524 |
518 var item = new cr.ui.MenuItem(); | 525 var item = new cr.ui.MenuItem(); |
519 item.label = loadTimeData.getString('VIDEO_PLAYER_PLAY_THIS_COMPUTER'); | 526 item.label = loadTimeData.getString('VIDEO_PLAYER_PLAY_THIS_COMPUTER'); |
520 item.castLabel = ''; | 527 item.castLabel = ''; |
521 item.addEventListener('activate', this.onCastSelected_.wrap(this, null)); | 528 item.addEventListener('activate', this.onCastSelected_.wrap(this, null)); |
522 menu.appendChild(item); | 529 menu.appendChild(item); |
523 | 530 |
524 for (var i = 0; i < casts.length; i++) { | 531 for (var i = 0; i < casts.length; i++) { |
525 var item = new cr.ui.MenuItem(); | 532 var item = new cr.ui.MenuItem(); |
526 item.label = casts[i].friendlyName; | 533 item.label = casts[i].friendlyName; |
527 item.castLabel = casts[i].label; | 534 item.castLabel = casts[i].label; |
528 item.addEventListener('activate', | 535 item.addEventListener('activate', |
529 this.onCastSelected_.wrap(this, casts[i])); | 536 this.onCastSelected_.wrap(this, casts[i])); |
530 menu.appendChild(item); | 537 menu.appendChild(item); |
531 } | 538 } |
532 this.updateCheckOnCastMenu_(); | 539 this.updateCheckOnCastMenu_(); |
533 button.classList.remove('hidden'); | 540 videoPlayerElement.setAttribute('cast-available', true); |
534 }; | 541 }; |
535 | 542 |
536 /** | 543 /** |
537 * Updates the check status of the cast menu items. | 544 * Updates the check status of the cast menu items. |
538 * @private | 545 * @private |
539 */ | 546 */ |
540 VideoPlayer.prototype.updateCheckOnCastMenu_ = function() { | 547 VideoPlayer.prototype.updateCheckOnCastMenu_ = function() { |
541 var menu = document.querySelector('#cast-menu'); | 548 var menu = document.querySelector('#cast-menu'); |
542 var menuItems = menu.menuItems; | 549 var menuItems = menu.menuItems; |
543 for (var i = 0; i < menuItems.length; i++) { | 550 for (var i = 0; i < menuItems.length; i++) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 var initPromise = Promise.all( | 613 var initPromise = Promise.all( |
607 [new Promise(initVideos.wrap(null)), | 614 [new Promise(initVideos.wrap(null)), |
608 new Promise(initStrings.wrap(null)), | 615 new Promise(initStrings.wrap(null)), |
609 new Promise(util.addPageLoadHandler.wrap(null))]); | 616 new Promise(util.addPageLoadHandler.wrap(null))]); |
610 | 617 |
611 initPromise.then(function(results) { | 618 initPromise.then(function(results) { |
612 var videos = results[0]; | 619 var videos = results[0]; |
613 player.prepare(videos); | 620 player.prepare(videos); |
614 return new Promise(player.playFirstVideo.wrap(player)); | 621 return new Promise(player.playFirstVideo.wrap(player)); |
615 }.wrap(null)); | 622 }.wrap(null)); |
OLD | NEW |