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

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 comment Created 6 years, 5 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 videoPlayerElement.setAttribute('casting', true);
278 this.videoElement_ = new CastVideoElement();
279 this.controls.attachMedia(this.videoElement_);
280 278
281 document.querySelector('#cast-name-label').textContent = 279 document.querySelector('#cast-name-label').textContent =
282 loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON'); 280 loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON');
283 document.querySelector('#cast-name').textContent = 281 document.querySelector('#cast-name').textContent =
284 this.currentCast_.friendlyName; 282 this.currentCast_.friendlyName;
283
284 var downloadUrlPromise = new Promise(function(fulfill, reject) {
285 chrome.fileBrowserPrivate.getDownloadUrl(video.url, fulfill);
286 });
287
288 var mimePromise = new Promise(function(fulfill, reject) {
289 chrome.fileBrowserPrivate.getDriveEntryProperties(
290 [video.entry.toURL()], fulfill);
291 });
292
293 videoElementInitializePromise =
294 Promise.all([downloadUrlPromise, mimePromise]).then(function(results) {
295 var downloadUrl = results[0];
296 var props = results[1];
297 var mime = '';
298 if (!props || props.length === 0 || !props[0].contentMimeType) {
299 // TODO(yoshiki): Adds a logic to guess the mime.
300 } else {
301 mime = props[0].contentMimeType;
302 }
303
304 return new Promise(function(fulfill, reject) {
305 chrome.cast.requestSession(
306 fulfill, reject, undefined, this.currentCast_.label);
307 }).then(function(session) {
308 var mediaInfo = new chrome.cast.media.MediaInfo(downloadUrl);
309 mediaInfo.contentType = mime;
310 this.videoElement_ = new CastVideoElement(mediaInfo, session);
311 this.controls.attachMedia(this.videoElement_);
312 }.bind(this));
313 }.bind(this));
285 } else { 314 } else {
286 videoPlayerElement.removeAttribute('casting'); 315 videoPlayerElement.removeAttribute('casting');
287 316
288 this.videoElement_ = document.createElement('video'); 317 this.videoElement_ = document.createElement('video');
289 document.querySelector('#video-container').appendChild(this.videoElement_); 318 document.querySelector('#video-container').appendChild(
319 this.videoElement_);
290 320
291 this.controls.attachMedia(this.videoElement_); 321 this.controls.attachMedia(this.videoElement_);
292 this.videoElement_.src = video.url; 322 this.videoElement_.src = video.url;
323
324 videoElementInitializePromise = Promise.resolve();
293 } 325 }
294 326
295 this.videoElement_.load(); 327 videoElementInitializePromise.then(
328 function() {
329 this.videoElement_.load();
296 330
297 if (opt_callback) { 331 if (opt_callback) {
298 var handler = function(currentPos, event) { 332 var handler = function(currentPos, event) {
299 console.log('loaded: ', currentPos, this.currentPos_); 333 if (currentPos === this.currentPos_)
300 if (currentPos === this.currentPos_) 334 opt_callback();
301 opt_callback(); 335 this.videoElement_.removeEventListener('loadedmetadata', handler);
302 this.videoElement_.removeEventListener('loadedmetadata', handler); 336 }.wrap(this, this.currentPos_);
303 }.wrap(this, this.currentPos_);
304 337
305 this.videoElement_.addEventListener('loadedmetadata', handler); 338 this.videoElement_.addEventListener('loadedmetadata', handler);
306 } 339 }
340 }.bind(this),
341 function videoElementInitializePromiseRejected() {
342 console.error('Failed to initialize the video element.',
343 error.stack || error);
344 this.controls_.showErrorMessage('GALLERY_VIDEO_ERROR');
345 }.bind(this));
307 }; 346 };
308 347
309 /** 348 /**
310 * Plays the first video. 349 * Plays the first video.
311 */ 350 */
312 VideoPlayer.prototype.playFirstVideo = function() { 351 VideoPlayer.prototype.playFirstVideo = function() {
313 this.currentPos_ = 0; 352 this.currentPos_ = 0;
314 this.reloadCurrentVideo_(this.onFirstVideoReady_.wrap(this)); 353 this.reloadCurrentVideo_(this.onFirstVideoReady_.wrap(this));
315 }; 354 };
316 355
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 var initPromise = Promise.all( 518 var initPromise = Promise.all(
480 [new Promise(initVideos.wrap(null)), 519 [new Promise(initVideos.wrap(null)),
481 new Promise(initStrings.wrap(null)), 520 new Promise(initStrings.wrap(null)),
482 new Promise(util.addPageLoadHandler.wrap(null))]); 521 new Promise(util.addPageLoadHandler.wrap(null))]);
483 522
484 initPromise.then(function(results) { 523 initPromise.then(function(results) {
485 var videos = results[0]; 524 var videos = results[0];
486 player.prepare(videos); 525 player.prepare(videos);
487 return new Promise(player.playFirstVideo.wrap(player)); 526 return new Promise(player.playFirstVideo.wrap(player));
488 }.wrap(null)); 527 }.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