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

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

Issue 542643003: Video Player: Keep the display awake during playing a video (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Stop keepawake on pause, and resume it on play. Created 6 years, 3 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
« no previous file with comments | « no previous file | ui/file_manager/video_player/manifest.json » ('j') | 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 loadTimeData.getString('VIDEO_PLAYER_PLAY_ON')); 257 loadTimeData.getString('VIDEO_PLAYER_PLAY_ON'));
258 258
259 document.addEventListener('keydown', reloadVideo); 259 document.addEventListener('keydown', reloadVideo);
260 document.addEventListener('click', reloadVideo); 260 document.addEventListener('click', reloadVideo);
261 }; 261 };
262 262
263 /** 263 /**
264 * Unloads the player. 264 * Unloads the player.
265 */ 265 */
266 function unload() { 266 function unload() {
267 // Releases keep awake just in case (should be released on unloading video).
268 chrome.power.releaseKeepAwake();
269
267 if (!player.controls || !player.controls.getMedia()) 270 if (!player.controls || !player.controls.getMedia())
268 return; 271 return;
269 272
270 player.controls.savePosition(true /* exiting */); 273 player.controls.savePosition(true /* exiting */);
271 player.controls.cleanup(); 274 player.controls.cleanup();
272 } 275 }
273 276
274 /** 277 /**
275 * Loads the video file. 278 * Loads the video file.
276 * @param {Object} video Data of the video file. 279 * @param {Object} video Data of the video file.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 if (opt_callback) 376 if (opt_callback)
374 opt_callback(); 377 opt_callback();
375 videoPlayerElement.removeAttribute('loading'); 378 videoPlayerElement.removeAttribute('loading');
376 this.controls.inactivityWatcher.disabled = false; 379 this.controls.inactivityWatcher.disabled = false;
377 } 380 }
378 381
379 this.videoElement_.removeEventListener('loadedmetadata', handler); 382 this.videoElement_.removeEventListener('loadedmetadata', handler);
380 }.wrap(this, this.currentPos_); 383 }.wrap(this, this.currentPos_);
381 384
382 this.videoElement_.addEventListener('loadedmetadata', handler); 385 this.videoElement_.addEventListener('loadedmetadata', handler);
386
387 this.videoElement_.addEventListener('play', function() {
388 chrome.power.requestKeepAwake('display');
389 }.wrap());
390 this.videoElement_.addEventListener('pause', function() {
391 chrome.power.releaseKeepAwake();
392 }.wrap());
393
383 this.videoElement_.load(); 394 this.videoElement_.load();
384 callback(); 395 callback();
385 }.bind(this)). 396 }.bind(this)).
386 // In case of error. 397 // In case of error.
387 catch(function(error) { 398 catch(function(error) {
388 videoPlayerElement.removeAttribute('loading'); 399 videoPlayerElement.removeAttribute('loading');
389 console.error('Failed to initialize the video element.', 400 console.error('Failed to initialize the video element.',
390 error.stack || error); 401 error.stack || error);
391 this.controls_.showErrorMessage('GALLERY_VIDEO_ERROR'); 402 this.controls_.showErrorMessage('GALLERY_VIDEO_ERROR');
392 callback(); 403 callback();
393 }.bind(this)); 404 }.bind(this));
394 }.wrap(this)); 405 }.wrap(this));
395 }; 406 };
396 407
397 /** 408 /**
398 * Plays the first video. 409 * Plays the first video.
399 */ 410 */
400 VideoPlayer.prototype.playFirstVideo = function() { 411 VideoPlayer.prototype.playFirstVideo = function() {
401 this.currentPos_ = 0; 412 this.currentPos_ = 0;
402 this.reloadCurrentVideo(this.onFirstVideoReady_.wrap(this)); 413 this.reloadCurrentVideo(this.onFirstVideoReady_.wrap(this));
403 }; 414 };
404 415
405 /** 416 /**
406 * Unloads the current video. 417 * Unloads the current video.
407 * @param {boolean=} opt_keepSession If true, keep using the current session. 418 * @param {boolean=} opt_keepSession If true, keep using the current session.
408 * Otherwise, discards the session. 419 * Otherwise, discards the session.
409 */ 420 */
410 VideoPlayer.prototype.unloadVideo = function(opt_keepSession) { 421 VideoPlayer.prototype.unloadVideo = function(opt_keepSession) {
411 this.loadQueue_.run(function(callback) { 422 this.loadQueue_.run(function(callback) {
423 chrome.power.releaseKeepAwake();
424
412 if (this.videoElement_) { 425 if (this.videoElement_) {
413 // If the element has dispose method, call it (CastVideoElement has it). 426 // If the element has dispose method, call it (CastVideoElement has it).
414 if (this.videoElement_.dispose) 427 if (this.videoElement_.dispose)
415 this.videoElement_.dispose(); 428 this.videoElement_.dispose();
416 // Detach the previous video element, if exists. 429 // Detach the previous video element, if exists.
417 if (this.videoElement_.parentNode) 430 if (this.videoElement_.parentNode)
418 this.videoElement_.parentNode.removeChild(this.videoElement_); 431 this.videoElement_.parentNode.removeChild(this.videoElement_);
419 } 432 }
420 this.videoElement_ = null; 433 this.videoElement_ = null;
421 434
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 var initPromise = Promise.all( 660 var initPromise = Promise.all(
648 [new Promise(initVideos.wrap(null)), 661 [new Promise(initVideos.wrap(null)),
649 new Promise(initStrings.wrap(null)), 662 new Promise(initStrings.wrap(null)),
650 new Promise(util.addPageLoadHandler.wrap(null))]); 663 new Promise(util.addPageLoadHandler.wrap(null))]);
651 664
652 initPromise.then(function(results) { 665 initPromise.then(function(results) {
653 var videos = results[0]; 666 var videos = results[0];
654 player.prepare(videos); 667 player.prepare(videos);
655 return new Promise(player.playFirstVideo.wrap(player)); 668 return new Promise(player.playFirstVideo.wrap(player));
656 }.wrap(null)); 669 }.wrap(null));
OLDNEW
« no previous file with comments | « no previous file | ui/file_manager/video_player/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698