| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 this.controls_ = null; | 152 this.controls_ = null; |
| 153 this.videoElement_ = null; | 153 this.videoElement_ = null; |
| 154 this.videos_ = null; | 154 this.videos_ = null; |
| 155 this.currentPos_ = 0; | 155 this.currentPos_ = 0; |
| 156 | 156 |
| 157 this.currentSession_ = null; | 157 this.currentSession_ = null; |
| 158 this.currentCast_ = null; | 158 this.currentCast_ = null; |
| 159 | 159 |
| 160 this.loadQueue_ = new AsyncUtil.Queue(); | 160 this.loadQueue_ = new AsyncUtil.Queue(); |
| 161 | 161 |
| 162 this.onCastSessionUpdateBound_ = this.onCastSessionUpdate_.wrap(this); |
| 163 |
| 162 Object.seal(this); | 164 Object.seal(this); |
| 163 } | 165 } |
| 164 | 166 |
| 165 VideoPlayer.prototype = { | 167 VideoPlayer.prototype = { |
| 166 get controls() { | 168 get controls() { |
| 167 return this.controls_; | 169 return this.controls_; |
| 168 } | 170 } |
| 169 }; | 171 }; |
| 170 | 172 |
| 171 /** | 173 /** |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 326 |
| 325 videoElementInitializePromise = | 327 videoElementInitializePromise = |
| 326 media.isAvailableForCast().then(function(result) { | 328 media.isAvailableForCast().then(function(result) { |
| 327 if (!result) | 329 if (!result) |
| 328 return Promise.reject('No casts are available.'); | 330 return Promise.reject('No casts are available.'); |
| 329 | 331 |
| 330 return new Promise(function(fulfill, reject) { | 332 return new Promise(function(fulfill, reject) { |
| 331 chrome.cast.requestSession( | 333 chrome.cast.requestSession( |
| 332 fulfill, reject, undefined, this.currentCast_.label); | 334 fulfill, reject, undefined, this.currentCast_.label); |
| 333 }.bind(this)).then(function(session) { | 335 }.bind(this)).then(function(session) { |
| 336 session.addUpdateListener(this.onCastSessionUpdateBound_); |
| 337 |
| 334 this.currentSession_ = session; | 338 this.currentSession_ = session; |
| 335 this.videoElement_ = new CastVideoElement(media, session); | 339 this.videoElement_ = new CastVideoElement(media, session); |
| 336 this.controls.attachMedia(this.videoElement_); | 340 this.controls.attachMedia(this.videoElement_); |
| 337 }.bind(this)); | 341 }.bind(this)); |
| 338 }.bind(this)); | 342 }.bind(this)); |
| 339 } else { | 343 } else { |
| 340 videoPlayerElement.removeAttribute('casting'); | 344 videoPlayerElement.removeAttribute('casting'); |
| 341 | 345 |
| 342 this.videoElement_ = document.createElement('video'); | 346 this.videoElement_ = document.createElement('video'); |
| 343 document.querySelector('#video-container').appendChild( | 347 document.querySelector('#video-container').appendChild( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 if (this.videoElement_.dispose) | 410 if (this.videoElement_.dispose) |
| 407 this.videoElement_.dispose(); | 411 this.videoElement_.dispose(); |
| 408 // Detach the previous video element, if exists. | 412 // Detach the previous video element, if exists. |
| 409 if (this.videoElement_.parentNode) | 413 if (this.videoElement_.parentNode) |
| 410 this.videoElement_.parentNode.removeChild(this.videoElement_); | 414 this.videoElement_.parentNode.removeChild(this.videoElement_); |
| 411 } | 415 } |
| 412 this.videoElement_ = null; | 416 this.videoElement_ = null; |
| 413 | 417 |
| 414 if (!opt_keepSession && this.currentSession_) { | 418 if (!opt_keepSession && this.currentSession_) { |
| 415 this.currentSession_.stop(callback, callback); | 419 this.currentSession_.stop(callback, callback); |
| 420 this.currentSession_.removeUpdateListener(this.onCastSessionUpdateBound_); |
| 416 this.currentSession_ = null; | 421 this.currentSession_ = null; |
| 417 } else { | 422 } else { |
| 418 callback(); | 423 callback(); |
| 419 } | 424 } |
| 420 }.wrap(this)); | 425 }.wrap(this)); |
| 421 }; | 426 }; |
| 422 | 427 |
| 423 /** | 428 /** |
| 424 * Called when the first video is ready after starting to load. | 429 * Called when the first video is ready after starting to load. |
| 425 * @private | 430 * @private |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 } | 577 } |
| 573 } | 578 } |
| 574 }; | 579 }; |
| 575 | 580 |
| 576 /** | 581 /** |
| 577 * Called when the current cast is disappear from the cast list. | 582 * Called when the current cast is disappear from the cast list. |
| 578 * @private | 583 * @private |
| 579 */ | 584 */ |
| 580 VideoPlayer.prototype.onCurrentCastDisappear_ = function() { | 585 VideoPlayer.prototype.onCurrentCastDisappear_ = function() { |
| 581 this.currentCast_ = null; | 586 this.currentCast_ = null; |
| 587 this.currentSession_.removeUpdateListener(this.onCastSessionUpdateBound_); |
| 582 this.currentSession_ = null; | 588 this.currentSession_ = null; |
| 583 this.controls.showErrorMessage('GALLERY_VIDEO_DECODING_ERROR'); | 589 this.controls.showErrorMessage('GALLERY_VIDEO_DECODING_ERROR'); |
| 584 this.unloadVideo(); | 590 this.unloadVideo(); |
| 585 }; | 591 }; |
| 586 | 592 |
| 587 /** | 593 /** |
| 594 * This method should be called when the session is updated. |
| 595 * @param {boolean} alive Whether the session is alive or not. |
| 596 * @private |
| 597 */ |
| 598 VideoPlayer.prototype.onCastSessionUpdate_ = function(alive) { |
| 599 if (!alive) |
| 600 this.unloadVideo(); |
| 601 }; |
| 602 |
| 603 /** |
| 588 * Initialize the list of videos. | 604 * Initialize the list of videos. |
| 589 * @param {function(Array.<Object>)} callback Called with the video list when | 605 * @param {function(Array.<Object>)} callback Called with the video list when |
| 590 * it is ready. | 606 * it is ready. |
| 591 */ | 607 */ |
| 592 function initVideos(callback) { | 608 function initVideos(callback) { |
| 593 if (window.videos) { | 609 if (window.videos) { |
| 594 var videos = window.videos; | 610 var videos = window.videos; |
| 595 window.videos = null; | 611 window.videos = null; |
| 596 callback(videos); | 612 callback(videos); |
| 597 return; | 613 return; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 621 var initPromise = Promise.all( | 637 var initPromise = Promise.all( |
| 622 [new Promise(initVideos.wrap(null)), | 638 [new Promise(initVideos.wrap(null)), |
| 623 new Promise(initStrings.wrap(null)), | 639 new Promise(initStrings.wrap(null)), |
| 624 new Promise(util.addPageLoadHandler.wrap(null))]); | 640 new Promise(util.addPageLoadHandler.wrap(null))]); |
| 625 | 641 |
| 626 initPromise.then(function(results) { | 642 initPromise.then(function(results) { |
| 627 var videos = results[0]; | 643 var videos = results[0]; |
| 628 player.prepare(videos); | 644 player.prepare(videos); |
| 629 return new Promise(player.playFirstVideo.wrap(player)); | 645 return new Promise(player.playFirstVideo.wrap(player)); |
| 630 }.wrap(null)); | 646 }.wrap(null)); |
| OLD | NEW |