OLD | NEW |
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 * Display error message. | 6 * Display error message. |
7 * @param {string} opt_message Message id. | 7 * @param {string} opt_message Message id. |
8 */ | 8 */ |
9 function onError(opt_message) { | 9 function onError(opt_message) { |
10 var errorBanner = document.querySelector('#error'); | 10 var errorBanner = document.querySelector('#error'); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 inactivityWatcher.stopActivity(); | 44 inactivityWatcher.stopActivity(); |
45 } | 45 } |
46 | 46 |
47 FullWindowVideoControls.prototype = { __proto__: VideoControls.prototype }; | 47 FullWindowVideoControls.prototype = { __proto__: VideoControls.prototype }; |
48 | 48 |
49 /** | 49 /** |
50 * Save the current play state in the location hash so that it survives | 50 * Save the current play state in the location hash so that it survives |
51 * the page reload. | 51 * the page reload. |
52 */ | 52 */ |
53 FullWindowVideoControls.prototype.onPlayStateChanged = function() { | 53 FullWindowVideoControls.prototype.onPlayStateChanged = function() { |
54 if (!this.getMedia().duration) | 54 this.encodeStateIntoLocation(); |
55 return; | |
56 | |
57 var playState = (this.isPlaying() ? 'play' : 'pause') + '=' + | |
58 this.getMedia().currentTime.toFixed(2); | |
59 | |
60 var newLocation = document.location.origin + document.location.pathname + | |
61 document.location.search + '#' + playState; | |
62 | |
63 history.replaceState(undefined, playState, newLocation); | |
64 }; | 55 }; |
65 | 56 |
66 /** | 57 /** |
67 * Resume the play state after the video is loaded. | 58 * Restore the play state after the video is loaded. |
68 */ | 59 */ |
69 FullWindowVideoControls.prototype.resumePosition = function() { | 60 FullWindowVideoControls.prototype.restorePlayState = function() { |
70 var video = this.getMedia(); | 61 if (!this.decodeStateFromLocation()) { |
71 | 62 VideoControls.prototype.restorePlayState.apply(this, arguments); |
72 var playState = document.location.hash.substring(1); | 63 this.play(); |
73 if (playState) { | |
74 var parts = playState.split('='); | |
75 video.currentTime = parseFloat(parts[1]); | |
76 if (parts[0] != 'pause') | |
77 video.play(); | |
78 } else { | |
79 VideoControls.prototype.resumePosition.apply(this, arguments); | |
80 video.play(); | |
81 } | 64 } |
82 }; | 65 }; |
83 | 66 |
84 /** | 67 /** |
85 * Initialize the video player window. | 68 * Initialize the video player window. |
86 */ | 69 */ |
87 function loadVideoPlayer() { | 70 function loadVideoPlayer() { |
88 document.oncontextmenu = function(e) { e.preventDefault(); }; | 71 document.oncontextmenu = function(e) { e.preventDefault(); }; |
89 document.ondragstart = function(e) { e.preventDefault() }; | 72 document.ondragstart = function(e) { e.preventDefault() }; |
90 | 73 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 var video = document.querySelector('video'); | 107 var video = document.querySelector('video'); |
125 video.src = src; | 108 video.src = src; |
126 video.load(); | 109 video.load(); |
127 controls.attachMedia(video); | 110 controls.attachMedia(video); |
128 }); | 111 }); |
129 }); | 112 }); |
130 }); | 113 }); |
131 } | 114 } |
132 | 115 |
133 document.addEventListener('DOMContentLoaded', loadVideoPlayer); | 116 document.addEventListener('DOMContentLoaded', loadVideoPlayer); |
OLD | NEW |