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 /** | 5 /** |
6 * @param {!HTMLElement} playerContainer Main container. | 6 * @param {!HTMLElement} playerContainer Main container. |
7 * @param {!HTMLElement} videoContainer Container for the video element. | 7 * @param {!HTMLElement} videoContainer Container for the video element. |
8 * @param {!HTMLElement} controlsContainer Container for video controls. | 8 * @param {!HTMLElement} controlsContainer Container for video controls. |
9 * @constructor | 9 * @constructor |
10 * @struct | 10 * @struct |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 return Promise.reject('No casts are available.'); | 359 return Promise.reject('No casts are available.'); |
360 | 360 |
361 return new Promise(function(fulfill, reject) { | 361 return new Promise(function(fulfill, reject) { |
362 chrome.cast.requestSession( | 362 chrome.cast.requestSession( |
363 fulfill, reject, undefined, this.currentCast_.label); | 363 fulfill, reject, undefined, this.currentCast_.label); |
364 }.bind(this)).then(function(session) { | 364 }.bind(this)).then(function(session) { |
365 session.addUpdateListener(this.onCastSessionUpdateBound_); | 365 session.addUpdateListener(this.onCastSessionUpdateBound_); |
366 | 366 |
367 this.currentSession_ = session; | 367 this.currentSession_ = session; |
368 this.videoElement_ = new CastVideoElement(media, session); | 368 this.videoElement_ = new CastVideoElement(media, session); |
369 this.controls.attachMedia(this.videoElement_); | |
370 }.bind(this)); | 369 }.bind(this)); |
371 }.bind(this)); | 370 }.bind(this)); |
372 } else { | 371 } else { |
373 metrics.recordPlayType(metrics.PLAY_TYPE.LOCAL); | 372 metrics.recordPlayType(metrics.PLAY_TYPE.LOCAL); |
374 videoPlayerElement.removeAttribute('casting'); | 373 videoPlayerElement.removeAttribute('casting'); |
375 | 374 |
376 this.videoElement_ = document.createElement('video'); | 375 this.videoElement_ = document.createElement('video'); |
377 getRequiredElement('video-container').appendChild(this.videoElement_); | 376 getRequiredElement('video-container').appendChild(this.videoElement_); |
378 | 377 |
379 var videoUrl = video.toURL(); | 378 var videoUrl = video.toURL(); |
380 this.controls.attachMedia(this.videoElement_); | |
381 var source = document.createElement('source'); | 379 var source = document.createElement('source'); |
382 source.src = videoUrl; | 380 source.src = videoUrl; |
383 this.videoElement_.appendChild(source); | 381 this.videoElement_.appendChild(source); |
384 | 382 |
385 media.isAvailableForCast().then(function(result) { | 383 media.isAvailableForCast().then(function(result) { |
386 if (result) | 384 if (result) |
387 videoPlayerElement.setAttribute('castable', true); | 385 videoPlayerElement.setAttribute('castable', true); |
388 else | 386 else |
389 videoPlayerElement.removeAttribute('castable'); | 387 videoPlayerElement.removeAttribute('castable'); |
390 }).catch(function() { | 388 }).catch(function() { |
(...skipping 26 matching lines...) Expand all Loading... |
417 this.videoElement_.addEventListener('loadedmetadata', handler); | 415 this.videoElement_.addEventListener('loadedmetadata', handler); |
418 | 416 |
419 this.videoElement_.addEventListener('play', function() { | 417 this.videoElement_.addEventListener('play', function() { |
420 chrome.power.requestKeepAwake('display'); | 418 chrome.power.requestKeepAwake('display'); |
421 this.updateInactivityWatcherState_(); | 419 this.updateInactivityWatcherState_(); |
422 }.wrap(this)); | 420 }.wrap(this)); |
423 this.videoElement_.addEventListener('pause', function() { | 421 this.videoElement_.addEventListener('pause', function() { |
424 chrome.power.releaseKeepAwake(); | 422 chrome.power.releaseKeepAwake(); |
425 this.updateInactivityWatcherState_(); | 423 this.updateInactivityWatcherState_(); |
426 }.wrap(this)); | 424 }.wrap(this)); |
| 425 this.controls.attachMedia(this.videoElement_); |
427 // TODO(ryoh): | 426 // TODO(ryoh): |
428 // If you modify the video element that is already inserted, | 427 // If you modify the video element that is already inserted, |
429 // you have to call load() method. | 428 // you have to call load() method. |
430 // https://dev.w3.org/html5/spec-author-view/video.html | 429 // https://dev.w3.org/html5/spec-author-view/video.html |
431 // But we always create new video element (see above), | 430 // But we always create new video element (see above), |
432 // we don't have to call load(). | 431 // we don't have to call load(). |
433 // If you call load() method here, | 432 // If you call load() method here, |
434 // you can't see subtitles. | 433 // you can't see subtitles. |
435 // (It might be a bug: https://crbug.com/594537) | 434 // (It might be a bug: https://crbug.com/594537) |
436 //this.videoElement_.load(); | 435 //this.videoElement_.load(); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 return new Promise(function(fulfill, reject) { | 741 return new Promise(function(fulfill, reject) { |
743 util.URLsToEntries(window.appState.items, function(entries) { | 742 util.URLsToEntries(window.appState.items, function(entries) { |
744 metrics.recordOpenVideoPlayerAction(); | 743 metrics.recordOpenVideoPlayerAction(); |
745 metrics.recordNumberOfOpenedFiles(entries.length); | 744 metrics.recordNumberOfOpenedFiles(entries.length); |
746 | 745 |
747 player.prepare(entries); | 746 player.prepare(entries); |
748 player.playFirstVideo(player, fulfill); | 747 player.playFirstVideo(player, fulfill); |
749 }.wrap()); | 748 }.wrap()); |
750 }.wrap()); | 749 }.wrap()); |
751 }.wrap()); | 750 }.wrap()); |
OLD | NEW |