Chromium Code Reviews| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 this.controls.attachMedia(this.videoElement_); | 369 this.controls.attachMedia(this.videoElement_); |
| 370 }.bind(this)); | 370 }.bind(this)); |
| 371 }.bind(this)); | 371 }.bind(this)); |
| 372 } else { | 372 } else { |
| 373 metrics.recordPlayType(metrics.PLAY_TYPE.LOCAL); | 373 metrics.recordPlayType(metrics.PLAY_TYPE.LOCAL); |
| 374 videoPlayerElement.removeAttribute('casting'); | 374 videoPlayerElement.removeAttribute('casting'); |
| 375 | 375 |
| 376 this.videoElement_ = document.createElement('video'); | 376 this.videoElement_ = document.createElement('video'); |
| 377 getRequiredElement('video-container').appendChild(this.videoElement_); | 377 getRequiredElement('video-container').appendChild(this.videoElement_); |
| 378 | 378 |
| 379 var videoUrl = video.toURL(); | |
| 379 this.controls.attachMedia(this.videoElement_); | 380 this.controls.attachMedia(this.videoElement_); |
| 380 this.videoElement_.src = video.toURL(); | 381 var source = document.createElement('source'); |
| 382 source.src = videoUrl; | |
| 383 this.videoElement_.appendChild(source); | |
| 381 | 384 |
| 382 media.isAvailableForCast().then(function(result) { | 385 media.isAvailableForCast().then(function(result) { |
| 383 if (result) | 386 if (result) |
| 384 videoPlayerElement.setAttribute('castable', true); | 387 videoPlayerElement.setAttribute('castable', true); |
| 385 else | 388 else |
| 386 videoPlayerElement.removeAttribute('castable'); | 389 videoPlayerElement.removeAttribute('castable'); |
| 387 }).catch(function() { | 390 }).catch(function() { |
| 388 videoPlayerElement.setAttribute('castable', true); | 391 videoPlayerElement.setAttribute('castable', true); |
| 389 }); | 392 }); |
| 390 | 393 |
| 391 videoElementInitializePromise = Promise.resolve(); | 394 videoElementInitializePromise = this.loadSubtitles_(videoUrl) |
| 395 .then(function(subltitleUrl) { | |
| 396 if (subltitleUrl) { | |
| 397 var track = document.createElement('track'); | |
| 398 track.src = subltitleUrl; | |
| 399 track.kind = 'subtitles'; | |
| 400 track.default = true; | |
| 401 this.videoElement_.appendChild(track); | |
| 402 } | |
| 403 return Promise.resolve(); | |
|
yoshiki
2016/03/14 04:10:52
nit: returning resolve is unnecessary. please remo
ryoh
2016/03/14 13:45:25
Done.
| |
| 404 }.bind(this)); | |
| 392 } | 405 } |
| 393 | |
| 394 videoElementInitializePromise | 406 videoElementInitializePromise |
| 395 .then(function() { | 407 .then(function() { |
| 396 var handler = function(currentPos) { | 408 var handler = function(currentPos) { |
| 397 if (currentPos === this.currentPos_) { | 409 if (currentPos === this.currentPos_) { |
| 398 if (opt_callback) | 410 if (opt_callback) |
| 399 opt_callback(); | 411 opt_callback(); |
| 400 videoPlayerElement.removeAttribute('loading'); | 412 videoPlayerElement.removeAttribute('loading'); |
| 401 } | 413 } |
| 402 | 414 |
| 403 this.videoElement_.removeEventListener('loadedmetadata', handler); | 415 this.videoElement_.removeEventListener('loadedmetadata', handler); |
| 404 }.wrap(this, this.currentPos_); | 416 }.wrap(this, this.currentPos_); |
| 405 | 417 |
| 406 this.videoElement_.addEventListener('loadedmetadata', handler); | 418 this.videoElement_.addEventListener('loadedmetadata', handler); |
| 407 | 419 |
| 408 this.videoElement_.addEventListener('play', function() { | 420 this.videoElement_.addEventListener('play', function() { |
| 409 chrome.power.requestKeepAwake('display'); | 421 chrome.power.requestKeepAwake('display'); |
| 410 this.updateInactivityWatcherState_(); | 422 this.updateInactivityWatcherState_(); |
| 411 }.wrap(this)); | 423 }.wrap(this)); |
| 412 this.videoElement_.addEventListener('pause', function() { | 424 this.videoElement_.addEventListener('pause', function() { |
| 413 chrome.power.releaseKeepAwake(); | 425 chrome.power.releaseKeepAwake(); |
| 414 this.updateInactivityWatcherState_(); | 426 this.updateInactivityWatcherState_(); |
| 415 }.wrap(this)); | 427 }.wrap(this)); |
| 416 | 428 |
| 417 this.videoElement_.load(); | |
|
ryoh
2016/03/11 15:11:58
Why do we need this line?
It seems 'loadedmetadata
yoshiki
2016/03/14 04:10:52
According to the spec, we need to call load() unle
ryoh
2016/03/14 13:45:25
Yeah, if we **modified** src attribute, you have t
| |
| 418 callback(); | 429 callback(); |
| 419 }.bind(this)) | 430 }.bind(this)) |
| 420 // In case of error. | 431 // In case of error. |
| 421 .catch(function(error) { | 432 .catch(function(error) { |
| 422 if (this.currentCast_) | 433 if (this.currentCast_) |
| 423 metrics.recordCastVideoErrorAction(); | 434 metrics.recordCastVideoErrorAction(); |
| 424 | 435 |
| 425 videoPlayerElement.removeAttribute('loading'); | 436 videoPlayerElement.removeAttribute('loading'); |
| 426 console.error('Failed to initialize the video element.', | 437 console.error('Failed to initialize the video element.', |
| 427 error.stack || error); | 438 error.stack || error); |
| 428 this.controls_.showErrorMessage( | 439 this.controls_.showErrorMessage( |
| 429 'VIDEO_PLAYER_VIDEO_FILE_UNSUPPORTED'); | 440 'VIDEO_PLAYER_VIDEO_FILE_UNSUPPORTED'); |
| 430 callback(); | 441 callback(); |
| 431 }.bind(this)); | 442 }.bind(this)); |
| 432 }.wrap(this)); | 443 }.wrap(this)); |
| 433 }; | 444 }; |
| 434 | 445 |
| 446 VideoPlayer.prototype.loadSubtitles_ = function(url) { | |
|
yoshiki
2016/03/14 04:10:52
nit: Please write a JSdoc (short description of th
ryoh
2016/03/14 13:45:25
Done.
| |
| 447 var baseUrl = util.splitExtension(url)[0]; | |
| 448 var resolveLocalFileSystem = function(extension) { | |
|
yoshiki
2016/03/14 04:10:52
"resolveLocalFileSystem" looks confusing with reso
ryoh
2016/03/14 13:45:25
Sounds nice! Thank you.
| |
| 449 return new Promise( | |
| 450 window.webkitResolveLocalFileSystemURL.bind(null, baseUrl + extension)); | |
| 451 } | |
|
yoshiki
2016/03/14 04:10:52
nit: semicolon
ryoh
2016/03/14 13:45:25
Done.
| |
| 452 return resolveLocalFileSystem('.vtt').then(function(subtitle) { | |
| 453 return subtitle.toURL(); | |
| 454 }).catch(function() { | |
| 455 return ''; | |
| 456 }); | |
| 457 }; | |
| 458 | |
| 435 /** | 459 /** |
| 436 * Plays the first video. | 460 * Plays the first video. |
| 437 */ | 461 */ |
| 438 VideoPlayer.prototype.playFirstVideo = function() { | 462 VideoPlayer.prototype.playFirstVideo = function() { |
| 439 this.currentPos_ = 0; | 463 this.currentPos_ = 0; |
| 440 this.reloadCurrentVideo(this.onFirstVideoReady_.wrap(this)); | 464 this.reloadCurrentVideo(this.onFirstVideoReady_.wrap(this)); |
| 441 }; | 465 }; |
| 442 | 466 |
| 443 /** | 467 /** |
| 444 * Unloads the current video. | 468 * Unloads the current video. |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 705 return new Promise(function(fulfill, reject) { | 729 return new Promise(function(fulfill, reject) { |
| 706 util.URLsToEntries(window.appState.items, function(entries) { | 730 util.URLsToEntries(window.appState.items, function(entries) { |
| 707 metrics.recordOpenVideoPlayerAction(); | 731 metrics.recordOpenVideoPlayerAction(); |
| 708 metrics.recordNumberOfOpenedFiles(entries.length); | 732 metrics.recordNumberOfOpenedFiles(entries.length); |
| 709 | 733 |
| 710 player.prepare(entries); | 734 player.prepare(entries); |
| 711 player.playFirstVideo(player, fulfill); | 735 player.playFirstVideo(player, fulfill); |
| 712 }.wrap()); | 736 }.wrap()); |
| 713 }.wrap()); | 737 }.wrap()); |
| 714 }.wrap()); | 738 }.wrap()); |
| OLD | NEW |