| 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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 /** | 477 /** |
| 478 * Invokes when a menuitem in the cast menu is selected. | 478 * Invokes when a menuitem in the cast menu is selected. |
| 479 * @param {Object} cast Selected element in the list of casts. | 479 * @param {Object} cast Selected element in the list of casts. |
| 480 */ | 480 */ |
| 481 VideoPlayer.prototype.onCastSelected_ = function(cast) { | 481 VideoPlayer.prototype.onCastSelected_ = function(cast) { |
| 482 // If the selected item is same as the current item, do nothing. | 482 // If the selected item is same as the current item, do nothing. |
| 483 if ((this.currentCast_ && this.currentCast_.label) === (cast && cast.label)) | 483 if ((this.currentCast_ && this.currentCast_.label) === (cast && cast.label)) |
| 484 return; | 484 return; |
| 485 | 485 |
| 486 this.currentCast_ = cast || null; | 486 this.currentCast_ = cast || null; |
| 487 this.updateCheckOnCastMenu_(); |
| 487 this.reloadCurrentVideo(); | 488 this.reloadCurrentVideo(); |
| 488 }; | 489 }; |
| 489 | 490 |
| 490 /** | 491 /** |
| 491 * Set the list of casts. | 492 * Set the list of casts. |
| 492 * @param {Array.<Object>} casts List of casts. | 493 * @param {Array.<Object>} casts List of casts. |
| 493 */ | 494 */ |
| 494 VideoPlayer.prototype.setCastList = function(casts) { | 495 VideoPlayer.prototype.setCastList = function(casts) { |
| 495 var button = document.querySelector('.cast-button'); | 496 var button = document.querySelector('.cast-button'); |
| 496 var menu = document.querySelector('#cast-menu'); | 497 var menu = document.querySelector('#cast-menu'); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 509 var currentCastAvailable = casts.some(function(cast) { | 510 var currentCastAvailable = casts.some(function(cast) { |
| 510 return this.currentCast_.label === cast.label; | 511 return this.currentCast_.label === cast.label; |
| 511 }.wrap(this)); | 512 }.wrap(this)); |
| 512 | 513 |
| 513 if (!currentCastAvailable) | 514 if (!currentCastAvailable) |
| 514 this.onCurrentCastDisappear_(); | 515 this.onCurrentCastDisappear_(); |
| 515 } | 516 } |
| 516 | 517 |
| 517 var item = new cr.ui.MenuItem(); | 518 var item = new cr.ui.MenuItem(); |
| 518 item.label = loadTimeData.getString('VIDEO_PLAYER_PLAY_THIS_COMPUTER'); | 519 item.label = loadTimeData.getString('VIDEO_PLAYER_PLAY_THIS_COMPUTER'); |
| 520 item.castLabel = ''; |
| 519 item.addEventListener('activate', this.onCastSelected_.wrap(this, null)); | 521 item.addEventListener('activate', this.onCastSelected_.wrap(this, null)); |
| 520 menu.appendChild(item); | 522 menu.appendChild(item); |
| 521 | 523 |
| 522 for (var i = 0; i < casts.length; i++) { | 524 for (var i = 0; i < casts.length; i++) { |
| 523 var item = new cr.ui.MenuItem(); | 525 var item = new cr.ui.MenuItem(); |
| 524 item.label = casts[i].friendlyName; | 526 item.label = casts[i].friendlyName; |
| 527 item.castLabel = casts[i].label; |
| 525 item.addEventListener('activate', | 528 item.addEventListener('activate', |
| 526 this.onCastSelected_.wrap(this, casts[i])); | 529 this.onCastSelected_.wrap(this, casts[i])); |
| 527 menu.appendChild(item); | 530 menu.appendChild(item); |
| 528 } | 531 } |
| 532 this.updateCheckOnCastMenu_(); |
| 529 button.classList.remove('hidden'); | 533 button.classList.remove('hidden'); |
| 530 }; | 534 }; |
| 531 | 535 |
| 532 /** | 536 /** |
| 537 * Updates the check status of the cast menu items. |
| 538 * @private |
| 539 */ |
| 540 VideoPlayer.prototype.updateCheckOnCastMenu_ = function() { |
| 541 var menu = document.querySelector('#cast-menu'); |
| 542 var menuItems = menu.menuItems; |
| 543 for (var i = 0; i < menuItems.length; i++) { |
| 544 var item = menuItems[i]; |
| 545 if (this.currentCast_ === null) { |
| 546 // Playing on this computer. |
| 547 if (item.castLabel === '') |
| 548 item.checked = true; |
| 549 else |
| 550 item.checked = false; |
| 551 } else { |
| 552 // Playing on cast device. |
| 553 if (item.castLabel === this.currentCast_.label) |
| 554 item.checked = true; |
| 555 else |
| 556 item.checked = false; |
| 557 } |
| 558 } |
| 559 }; |
| 560 |
| 561 /** |
| 533 * Called when the current cast is disappear from the cast list. | 562 * Called when the current cast is disappear from the cast list. |
| 534 * @private | 563 * @private |
| 535 */ | 564 */ |
| 536 VideoPlayer.prototype.onCurrentCastDisappear_ = function() { | 565 VideoPlayer.prototype.onCurrentCastDisappear_ = function() { |
| 537 this.currentCast_ = null; | 566 this.currentCast_ = null; |
| 538 this.currentSession_ = null; | 567 this.currentSession_ = null; |
| 539 this.controls.showErrorMessage('GALLERY_VIDEO_DECODING_ERROR'); | 568 this.controls.showErrorMessage('GALLERY_VIDEO_DECODING_ERROR'); |
| 540 this.unloadVideo(); | 569 this.unloadVideo(); |
| 541 }; | 570 }; |
| 542 | 571 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 var initPromise = Promise.all( | 606 var initPromise = Promise.all( |
| 578 [new Promise(initVideos.wrap(null)), | 607 [new Promise(initVideos.wrap(null)), |
| 579 new Promise(initStrings.wrap(null)), | 608 new Promise(initStrings.wrap(null)), |
| 580 new Promise(util.addPageLoadHandler.wrap(null))]); | 609 new Promise(util.addPageLoadHandler.wrap(null))]); |
| 581 | 610 |
| 582 initPromise.then(function(results) { | 611 initPromise.then(function(results) { |
| 583 var videos = results[0]; | 612 var videos = results[0]; |
| 584 player.prepare(videos); | 613 player.prepare(videos); |
| 585 return new Promise(player.playFirstVideo.wrap(player)); | 614 return new Promise(player.playFirstVideo.wrap(player)); |
| 586 }.wrap(null)); | 615 }.wrap(null)); |
| OLD | NEW |