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

Side by Side Diff: chrome/browser/resources/file_manager/js/image_editor/media_controls.js

Issue 9562003: Better resume for Video Player. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | « no previous file | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 * @fileoverview MediaControls class implements media playback controls 6 * @fileoverview MediaControls class implements media playback controls
7 * that exist outside of the audio/video HTML element. 7 * that exist outside of the audio/video HTML element.
8 */ 8 */
9 9
10 /** 10 /**
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 695
696 this.resumePositions_ = new TimeLimitedMap( 696 this.resumePositions_ = new TimeLimitedMap(
697 'VideoResumePosition', 697 'VideoResumePosition',
698 VideoControls.RESUME_POSITIONS_CAPACITY, 698 VideoControls.RESUME_POSITIONS_CAPACITY,
699 VideoControls.RESUME_POSITION_LIFETIME); 699 VideoControls.RESUME_POSITION_LIFETIME);
700 } 700 }
701 701
702 VideoControls.RESUME_POSITIONS_CAPACITY = 100; 702 VideoControls.RESUME_POSITIONS_CAPACITY = 100;
703 VideoControls.RESUME_POSITION_LIFETIME = 30 * 24 * 60 * 60 * 1000; // 30 days. 703 VideoControls.RESUME_POSITION_LIFETIME = 30 * 24 * 60 * 60 * 1000; // 30 days.
704 VideoControls.RESUME_MARGIN = 0.03; 704 VideoControls.RESUME_MARGIN = 0.03;
705 // Ignore the tail margin for videos shorter than 5 minutes. 705 VideoControls.RESUME_THRESHOLD = 5 * 60; // No resume for videos < 5 min.
706 VideoControls.RESUME_TAIL_MARGIN_THRESHOLD = 5 * 60;
707 VideoControls.RESUME_REWIND = 5; // Rewind 5 seconds back when resuming. 706 VideoControls.RESUME_REWIND = 5; // Rewind 5 seconds back when resuming.
708 707
709 VideoControls.prototype = { __proto__: MediaControls.prototype }; 708 VideoControls.prototype = { __proto__: MediaControls.prototype };
710 709
711 VideoControls.prototype.onMediaComplete = function() { 710 VideoControls.prototype.onMediaComplete = function() {
712 this.onMediaPlay_(false); // Just update the UI. 711 this.onMediaPlay_(false); // Just update the UI.
713 this.savePosition(); // This will effectively forget the position. 712 this.savePosition(); // This will effectively forget the position.
714 }; 713 };
715 714
716 VideoControls.prototype.togglePlayStateWithFeedback = function(e) { 715 VideoControls.prototype.togglePlayStateWithFeedback = function(e) {
(...skipping 28 matching lines...) Expand all
745 delay(function(){ 744 delay(function(){
746 self.stateIcon_.setAttribute( 745 self.stateIcon_.setAttribute(
747 'state', self.isPlaying() ? 'play' : 'pause'); 746 'state', self.isPlaying() ? 'play' : 'pause');
748 delay(hideStatusIcon, 1000); /* Twice the animation duration. */ 747 delay(hideStatusIcon, 1000); /* Twice the animation duration. */
749 }); 748 });
750 }); 749 });
751 }; 750 };
752 751
753 VideoControls.prototype.onMediaDuration_ = function() { 752 VideoControls.prototype.onMediaDuration_ = function() {
754 MediaControls.prototype.onMediaDuration_.apply(this, arguments); 753 MediaControls.prototype.onMediaDuration_.apply(this, arguments);
755 if (this.media_.duration && this.media_.seekable) { 754 if (this.media_.duration &&
755 this.media_.duration >= VideoControls.RESUME_THRESHOLD &&
756 this.media_.seekable) {
756 var position = this.resumePositions_.getValue(this.media_.src); 757 var position = this.resumePositions_.getValue(this.media_.src);
757 if (position) { 758 if (position) {
758 this.media_.currentTime = position; 759 this.media_.currentTime = position;
759 } 760 }
760 } 761 }
761 }; 762 };
762 763
763 VideoControls.prototype.togglePlayState = function(e) { 764 VideoControls.prototype.togglePlayState = function(e) {
764 if (this.isPlaying()) { 765 if (this.isPlaying()) {
765 // User gave the Pause command. 766 // User gave the Pause command.
766 this.savePosition(); 767 this.savePosition();
767 } 768 }
768 MediaControls.prototype.togglePlayState.apply(this, arguments); 769 MediaControls.prototype.togglePlayState.apply(this, arguments);
769 }; 770 };
770 771
771 VideoControls.prototype.savePosition = function() { 772 VideoControls.prototype.savePosition = function() {
772 if (!this.media_.duration) 773 if (!this.media_.duration ||
774 this.media_.duration_ < VideoControls.RESUME_THRESHOLD)
773 return; 775 return;
774 776
775 var ratio = this.media_.currentTime / this.media_.duration; 777 var ratio = this.media_.currentTime / this.media_.duration;
776 if (ratio < VideoControls.RESUME_MARGIN || 778 if (ratio < VideoControls.RESUME_MARGIN ||
777 (this.media_.duration >= VideoControls.RESUME_TAIL_MARGIN_THRESHOLD && 779 ratio > (1 - VideoControls.RESUME_MARGIN)) {
778 ratio > (1 - VideoControls.RESUME_MARGIN))) {
779 // We are too close to the beginning or the end. 780 // We are too close to the beginning or the end.
780 // Remove the resume position so that next time we start from the beginning. 781 // Remove the resume position so that next time we start from the beginning.
781 this.resumePositions_.removeValue(this.media_.src); 782 this.resumePositions_.removeValue(this.media_.src);
782 } else { 783 } else {
783 this.resumePositions_.setValue(this.media_.src, Math.floor(Math.max(0, 784 this.resumePositions_.setValue(this.media_.src, Math.floor(Math.max(0,
784 this.media_.currentTime - VideoControls.RESUME_REWIND))); 785 this.media_.currentTime - VideoControls.RESUME_REWIND)));
785 } 786 }
786 }; 787 };
787 788
788 /** 789 /**
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 AudioControls.prototype.onAdvanceClick_ = function(forward) { 923 AudioControls.prototype.onAdvanceClick_ = function(forward) {
923 if (!forward && 924 if (!forward &&
924 (this.getMedia().currentTime > AudioControls.TRACK_RESTART_THRESHOLD)) { 925 (this.getMedia().currentTime > AudioControls.TRACK_RESTART_THRESHOLD)) {
925 // We are far enough from the beginning of the current track. 926 // We are far enough from the beginning of the current track.
926 // Restart it instead of than skipping to the previous one. 927 // Restart it instead of than skipping to the previous one.
927 this.getMedia().currentTime = 0; 928 this.getMedia().currentTime = 0;
928 } else { 929 } else {
929 this.advanceTrack_(forward); 930 this.advanceTrack_(forward);
930 } 931 }
931 }; 932 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698