Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: ui/file_manager/video_player/js/video_player.js

Issue 412813002: Video Player: Support casting a video (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed the comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/file_manager/video_player/js/cast/cast_video_element.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 this.inactivityWatcher_.check(); 69 this.inactivityWatcher_.check();
70 } 70 }
71 71
72 FullWindowVideoControls.prototype = { __proto__: VideoControls.prototype }; 72 FullWindowVideoControls.prototype = { __proto__: VideoControls.prototype };
73 73
74 /** 74 /**
75 * Displays error message. 75 * Displays error message.
76 * 76 *
77 * @param {string} message Message id. 77 * @param {string} message Message id.
78 * @private
79 */ 78 */
80 FullWindowVideoControls.prototype.showErrorMessage_ = function(message) { 79 FullWindowVideoControls.prototype.showErrorMessage = function(message) {
81 var errorBanner = document.querySelector('#error'); 80 var errorBanner = document.querySelector('#error');
82 errorBanner.textContent = 81 errorBanner.textContent =
83 loadTimeData.getString(message); 82 loadTimeData.getString(message);
84 errorBanner.setAttribute('visible', 'true'); 83 errorBanner.setAttribute('visible', 'true');
85 84
86 // The window is hidden if the video has not loaded yet. 85 // The window is hidden if the video has not loaded yet.
87 chrome.app.window.current().show(); 86 chrome.app.window.current().show();
88 }; 87 };
89 88
90 /** 89 /**
91 * Handles playback (decoder) errors. 90 * Handles playback (decoder) errors.
92 * @private 91 * @private
93 */ 92 */
94 FullWindowVideoControls.prototype.onPlaybackError_ = function() { 93 FullWindowVideoControls.prototype.onPlaybackError_ = function() {
95 this.showErrorMessage_('GALLERY_VIDEO_DECODING_ERROR'); 94 this.showErrorMessage('GALLERY_VIDEO_DECODING_ERROR');
96 this.decodeErrorOccured = true; 95 this.decodeErrorOccured = true;
97 96
98 // Disable inactivity watcher, and disable the ui, by hiding tools manually. 97 // Disable inactivity watcher, and disable the ui, by hiding tools manually.
99 this.inactivityWatcher.disabled = true; 98 this.inactivityWatcher.disabled = true;
100 document.querySelector('#video-player').setAttribute('disabled', 'true'); 99 document.querySelector('#video-player').setAttribute('disabled', 'true');
101 100
102 // Detach the video element, since it may be unreliable and reset stored 101 // Detach the video element, since it may be unreliable and reset stored
103 // current playback time. 102 // current playback time.
104 this.cleanup(); 103 this.cleanup();
105 this.clearState(); 104 this.clearState();
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 videoPlayerElement.setAttribute('first-video', true); 265 videoPlayerElement.setAttribute('first-video', true);
267 else 266 else
268 videoPlayerElement.removeAttribute('first-video'); 267 videoPlayerElement.removeAttribute('first-video');
269 268
270 // Re-enables ui and hides error message if already displayed. 269 // Re-enables ui and hides error message if already displayed.
271 document.querySelector('#video-player').removeAttribute('disabled'); 270 document.querySelector('#video-player').removeAttribute('disabled');
272 document.querySelector('#error').removeAttribute('visible'); 271 document.querySelector('#error').removeAttribute('visible');
273 this.controls.inactivityWatcher.disabled = false; 272 this.controls.inactivityWatcher.disabled = false;
274 this.controls.decodeErrorOccured = false; 273 this.controls.decodeErrorOccured = false;
275 274
275 var videoElementInitializePromise;
276 if (this.currentCast_) { 276 if (this.currentCast_) {
277 videoPlayerElement.setAttribute('casting', true); 277 videoElementInitializePromise = new Promise(function(fulfill, reject) {
278 this.videoElement_ = new CastVideoElement(); 278 videoPlayerElement.setAttribute('casting', true);
279 this.controls.attachMedia(this.videoElement_);
280 279
281 document.querySelector('#cast-name-label').textContent = 280 document.querySelector('#cast-name-label').textContent =
282 loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON'); 281 loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON');
283 document.querySelector('#cast-name').textContent = 282 document.querySelector('#cast-name').textContent =
284 this.currentCast_.friendlyName; 283 this.currentCast_.friendlyName;
284
285 var downloadUrlPromise = new Promise(function(innerFulfill, innerReject) {
286 chrome.fileBrowserPrivate.getDownloadUrl(video.url, innerFulfill);
287 });
288
289 var mimePromise = new Promise(function(innerFulfill, innerReject) {
290 chrome.fileBrowserPrivate.getDriveEntryProperties(
291 [video.entry.toURL()],
292 function(props) {
293 if (!props || props.length === 0 || !props[0].contentMimeType) {
294 // TODO(yoshiki): Adds a logic to guess the mime.
295 innerFulfill('');
296 }
297 innerFulfill(props[0].contentMimeType);
298 }.wrap());
hirono 2014/07/24 05:46:09 The exception thrown in the callback will be repor
yoshiki 2014/07/24 06:03:22 Done.
299 });
300
301 Promise.all([downloadUrlPromise, mimePromise]).then(function(results) {
302 var downloadUrl = results[0];
303 var mime = results[1];
304
305 return new Promise(function(innerFulfill, innerReject) {
306 chrome.cast.requestSession(function(session) {
307 var mediaInfo = new chrome.cast.media.MediaInfo(downloadUrl);
308 mediaInfo.contentType = mime;
309 this.videoElement_ = new CastVideoElement(mediaInfo, session);
310 this.controls.attachMedia(this.videoElement_);
311 innerFulfill();
312 }.wrap(this), innerReject, undefined, this.currentCast_.label);
313 }.bind(this));
314 }.bind(this)).then(fulfill, reject);
315 }.bind(this));
285 } else { 316 } else {
286 videoPlayerElement.removeAttribute('casting'); 317 videoElementInitializePromise = new Promise(function(fulfill, reject) {
318 videoPlayerElement.removeAttribute('casting');
287 319
288 this.videoElement_ = document.createElement('video'); 320 this.videoElement_ = document.createElement('video');
289 document.querySelector('#video-container').appendChild(this.videoElement_); 321 document.querySelector('#video-container').appendChild(
322 this.videoElement_);
290 323
291 this.controls.attachMedia(this.videoElement_); 324 this.controls.attachMedia(this.videoElement_);
292 this.videoElement_.src = video.url; 325 this.videoElement_.src = video.url;
326 fulfill();
327 }.bind(this));
293 } 328 }
294 329
295 this.videoElement_.load(); 330 videoElementInitializePromise.then(
331 function() {
332 this.videoElement_.load();
296 333
297 if (opt_callback) { 334 if (opt_callback) {
298 var handler = function(currentPos, event) { 335 var handler = function(currentPos, event) {
299 console.log('loaded: ', currentPos, this.currentPos_); 336 if (currentPos === this.currentPos_)
300 if (currentPos === this.currentPos_) 337 opt_callback();
301 opt_callback(); 338 this.videoElement_.removeEventListener('loadedmetadata', handler);
302 this.videoElement_.removeEventListener('loadedmetadata', handler); 339 }.wrap(this, this.currentPos_);
303 }.wrap(this, this.currentPos_);
304 340
305 this.videoElement_.addEventListener('loadedmetadata', handler); 341 this.videoElement_.addEventListener('loadedmetadata', handler);
306 } 342 }
343 }.bind(this),
344 function videoElementInitializePromiseRejected() {
345 console.error('Failed to initialize the video element.',
346 error.stack || error);
347 this.controls_.showErrorMessage('GALLERY_VIDEO_ERROR');
348 }.bind(this));
307 }; 349 };
308 350
309 /** 351 /**
310 * Plays the first video. 352 * Plays the first video.
311 */ 353 */
312 VideoPlayer.prototype.playFirstVideo = function() { 354 VideoPlayer.prototype.playFirstVideo = function() {
313 this.currentPos_ = 0; 355 this.currentPos_ = 0;
314 this.reloadCurrentVideo_(this.onFirstVideoReady_.wrap(this)); 356 this.reloadCurrentVideo_(this.onFirstVideoReady_.wrap(this));
315 }; 357 };
316 358
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 var initPromise = Promise.all( 521 var initPromise = Promise.all(
480 [new Promise(initVideos.wrap(null)), 522 [new Promise(initVideos.wrap(null)),
481 new Promise(initStrings.wrap(null)), 523 new Promise(initStrings.wrap(null)),
482 new Promise(util.addPageLoadHandler.wrap(null))]); 524 new Promise(util.addPageLoadHandler.wrap(null))]);
483 525
484 initPromise.then(function(results) { 526 initPromise.then(function(results) {
485 var videos = results[0]; 527 var videos = results[0];
486 player.prepare(videos); 528 player.prepare(videos);
487 return new Promise(player.playFirstVideo.wrap(player)); 529 return new Promise(player.playFirstVideo.wrap(player));
488 }.wrap(null)); 530 }.wrap(null));
OLDNEW
« no previous file with comments | « ui/file_manager/video_player/js/cast/cast_video_element.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698