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

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

Issue 477603002: Video Player: Hide the cast icon on non-drive volume (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed the comment 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/css/header.css ('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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 function(results) { 298 function(results) {
299 var url = results[0]; 299 var url = results[0];
300 var token = results[1]; 300 var token = results[1];
301 document.querySelector('#thumbnail').style.backgroundImage = 301 document.querySelector('#thumbnail').style.backgroundImage =
302 'url(' + url + '&access_token=' + token + ')'; 302 'url(' + url + '&access_token=' + token + ')';
303 }).catch(function() { 303 }).catch(function() {
304 // Shows no image on error. 304 // Shows no image on error.
305 document.querySelector('#thumbnail').style.backgroundImage = ''; 305 document.querySelector('#thumbnail').style.backgroundImage = '';
306 }); 306 });
307 307
308 var media = new MediaManager(video.entry);
309
310 var videoElementInitializePromise; 308 var videoElementInitializePromise;
311 if (this.currentCast_) { 309 if (this.currentCast_) {
312 videoPlayerElement.setAttribute('casting', true); 310 videoPlayerElement.setAttribute('casting', true);
313 311
314 document.querySelector('#cast-name-label').textContent = 312 document.querySelector('#cast-name-label').textContent =
315 loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON'); 313 loadTimeData.getString('VIDEO_PLAYER_PLAYING_ON');
316 document.querySelector('#cast-name').textContent = 314 document.querySelector('#cast-name').textContent =
317 this.currentCast_.friendlyName; 315 this.currentCast_.friendlyName;
318 316
317 videoPlayerElement.setAttribute('castable', true);
318
319 videoElementInitializePromise = 319 videoElementInitializePromise =
320 media.isAvailableForCast().then(function(result) { 320 media.isAvailableForCast().then(function(result) {
321 if (!result) 321 if (!result)
322 return Promise.reject('No casts are available.'); 322 return Promise.reject('No casts are available.');
323 323
324 return new Promise(function(fulfill, reject) { 324 return new Promise(function(fulfill, reject) {
325 chrome.cast.requestSession( 325 chrome.cast.requestSession(
326 fulfill, reject, undefined, this.currentCast_.label); 326 fulfill, reject, undefined, this.currentCast_.label);
327 }.bind(this)).then(function(session) { 327 }.bind(this)).then(function(session) {
328 this.currentSession_ = session; 328 this.currentSession_ = session;
329 this.videoElement_ = new CastVideoElement(media, session); 329 this.videoElement_ = new CastVideoElement(media, session);
330 this.controls.attachMedia(this.videoElement_); 330 this.controls.attachMedia(this.videoElement_);
331 }.bind(this)); 331 }.bind(this));
332 }.bind(this)); 332 }.bind(this));
333 } else { 333 } else {
334 videoPlayerElement.removeAttribute('casting'); 334 videoPlayerElement.removeAttribute('casting');
335 335
336 this.videoElement_ = document.createElement('video'); 336 this.videoElement_ = document.createElement('video');
337 document.querySelector('#video-container').appendChild( 337 document.querySelector('#video-container').appendChild(
338 this.videoElement_); 338 this.videoElement_);
339 339
340 this.controls.attachMedia(this.videoElement_); 340 this.controls.attachMedia(this.videoElement_);
341 this.videoElement_.src = video.url; 341 this.videoElement_.src = video.url;
342 342
343 media.isAvailableForCast().then(function(result) {
344 if (result)
345 videoPlayerElement.setAttribute('castable', true);
346 else
347 videoPlayerElement.removeAttribute('castable');
348 }).catch(function() {
349 videoPlayerElement.setAttribute('castable', true);
350 });
351
343 videoElementInitializePromise = Promise.resolve(); 352 videoElementInitializePromise = Promise.resolve();
344 } 353 }
345 354
346 videoElementInitializePromise. 355 videoElementInitializePromise.
347 then(function() { 356 then(function() {
348 var handler = function(currentPos) { 357 var handler = function(currentPos) {
349 if (currentPos === this.currentPos_) { 358 if (currentPos === this.currentPos_) {
350 if (opt_callback) 359 if (opt_callback)
351 opt_callback(); 360 opt_callback();
352 videoPlayerElement.removeAttribute('loading'); 361 videoPlayerElement.removeAttribute('loading');
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 this.currentCast_ = cast || null; 495 this.currentCast_ = cast || null;
487 this.updateCheckOnCastMenu_(); 496 this.updateCheckOnCastMenu_();
488 this.reloadCurrentVideo(); 497 this.reloadCurrentVideo();
489 }; 498 };
490 499
491 /** 500 /**
492 * Set the list of casts. 501 * Set the list of casts.
493 * @param {Array.<Object>} casts List of casts. 502 * @param {Array.<Object>} casts List of casts.
494 */ 503 */
495 VideoPlayer.prototype.setCastList = function(casts) { 504 VideoPlayer.prototype.setCastList = function(casts) {
496 var button = document.querySelector('.cast-button'); 505 var videoPlayerElement = document.querySelector('#video-player');
497 var menu = document.querySelector('#cast-menu'); 506 var menu = document.querySelector('#cast-menu');
498 menu.innerHTML = ''; 507 menu.innerHTML = '';
499 508
500 // TODO(yoshiki): Handle the case that the current cast disappears. 509 // TODO(yoshiki): Handle the case that the current cast disappears.
501 510
502 if (casts.length === 0) { 511 if (casts.length === 0) {
503 button.classList.add('hidden'); 512 videoPlayerElement.removeAttribute('cast-available');
504 if (this.currentCast_) 513 if (this.currentCast_)
505 this.onCurrentCastDisappear_(); 514 this.onCurrentCastDisappear_();
506 return; 515 return;
507 } 516 }
508 517
509 if (this.currentCast_) { 518 if (this.currentCast_) {
510 var currentCastAvailable = casts.some(function(cast) { 519 var currentCastAvailable = casts.some(function(cast) {
511 return this.currentCast_.label === cast.label; 520 return this.currentCast_.label === cast.label;
512 }.wrap(this)); 521 }.wrap(this));
513 522
514 if (!currentCastAvailable) 523 if (!currentCastAvailable)
515 this.onCurrentCastDisappear_(); 524 this.onCurrentCastDisappear_();
516 } 525 }
517 526
518 var item = new cr.ui.MenuItem(); 527 var item = new cr.ui.MenuItem();
519 item.label = loadTimeData.getString('VIDEO_PLAYER_PLAY_THIS_COMPUTER'); 528 item.label = loadTimeData.getString('VIDEO_PLAYER_PLAY_THIS_COMPUTER');
520 item.castLabel = ''; 529 item.castLabel = '';
521 item.addEventListener('activate', this.onCastSelected_.wrap(this, null)); 530 item.addEventListener('activate', this.onCastSelected_.wrap(this, null));
522 menu.appendChild(item); 531 menu.appendChild(item);
523 532
524 for (var i = 0; i < casts.length; i++) { 533 for (var i = 0; i < casts.length; i++) {
525 var item = new cr.ui.MenuItem(); 534 var item = new cr.ui.MenuItem();
526 item.label = casts[i].friendlyName; 535 item.label = casts[i].friendlyName;
527 item.castLabel = casts[i].label; 536 item.castLabel = casts[i].label;
528 item.addEventListener('activate', 537 item.addEventListener('activate',
529 this.onCastSelected_.wrap(this, casts[i])); 538 this.onCastSelected_.wrap(this, casts[i]));
530 menu.appendChild(item); 539 menu.appendChild(item);
531 } 540 }
532 this.updateCheckOnCastMenu_(); 541 this.updateCheckOnCastMenu_();
533 button.classList.remove('hidden'); 542 videoPlayerElement.setAttribute('cast-available', true);
534 }; 543 };
535 544
536 /** 545 /**
537 * Updates the check status of the cast menu items. 546 * Updates the check status of the cast menu items.
538 * @private 547 * @private
539 */ 548 */
540 VideoPlayer.prototype.updateCheckOnCastMenu_ = function() { 549 VideoPlayer.prototype.updateCheckOnCastMenu_ = function() {
541 var menu = document.querySelector('#cast-menu'); 550 var menu = document.querySelector('#cast-menu');
542 var menuItems = menu.menuItems; 551 var menuItems = menu.menuItems;
543 for (var i = 0; i < menuItems.length; i++) { 552 for (var i = 0; i < menuItems.length; i++) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 var initPromise = Promise.all( 615 var initPromise = Promise.all(
607 [new Promise(initVideos.wrap(null)), 616 [new Promise(initVideos.wrap(null)),
608 new Promise(initStrings.wrap(null)), 617 new Promise(initStrings.wrap(null)),
609 new Promise(util.addPageLoadHandler.wrap(null))]); 618 new Promise(util.addPageLoadHandler.wrap(null))]);
610 619
611 initPromise.then(function(results) { 620 initPromise.then(function(results) {
612 var videos = results[0]; 621 var videos = results[0];
613 player.prepare(videos); 622 player.prepare(videos);
614 return new Promise(player.playFirstVideo.wrap(player)); 623 return new Promise(player.playFirstVideo.wrap(player));
615 }.wrap(null)); 624 }.wrap(null));
OLDNEW
« no previous file with comments | « ui/file_manager/video_player/css/header.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698