Skip to content

Commit a1fef07

Browse files
authored
Merge pull request #47 from voxel51/mediafragmentEndOfClipFail
Mediafragment end of clip fail
2 parents 5ef462f + b85a1e1 commit a1fef07

4 files changed

Lines changed: 147 additions & 38 deletions

File tree

src/js/renderers/videorenderer.js

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ VideoRenderer.prototype.initPlayerControls = function() {
120120
if (this._boolAutoplay) {
121121
this.eleVideo.toggleAttribute('autoplay', true);
122122
}
123-
if (this._boolLoop) {
124-
this.eleVideo.toggleAttribute('loop', true);
125-
}
123+
126124
if (this.player._boolHasPoster) {
127125
this.eleVideo.setAttribute('poster', this.player._loadingPosterURL);
128126
if (this.player._boolForcedSize) {
@@ -169,7 +167,6 @@ VideoRenderer.prototype.initPlayerControls = function() {
169167
if (self._boolSingleFrame ) {
170168
self.eleVideo.currentTime = self._mfBeginT;
171169
self._frameNumber = self._mfBeginF;
172-
// self.processFrame();
173170
}
174171

175172
// so that we see overlay and time stamp now that we are ready
@@ -179,6 +176,37 @@ VideoRenderer.prototype.initPlayerControls = function() {
179176
}
180177
});
181178

179+
this.eleVideo.addEventListener('ended', function() {
180+
if (self._boolLoop) {
181+
self.eleVideo.play();
182+
} else {
183+
self._boolPlaying = false;
184+
self.updateFromDynamicState();
185+
}
186+
});
187+
188+
189+
this.eleVideo.addEventListener('pause', function() {
190+
self.checkForFragmentReset(self.computeFrameNumber());
191+
if (self._boolPlaying && !self._lockToMF && !self._boolManualSeek
192+
&& !self.eleVideo.ended) {
193+
self.eleVideo.play();
194+
}
195+
});
196+
197+
// Update the seek bar as the video plays
198+
this.eleVideo.addEventListener('timeupdate', function() {
199+
// Calculate the slider value
200+
const value = (100 / self.eleVideo.duration) * self.eleVideo
201+
.currentTime;
202+
// Update the slider value
203+
self.eleSeekBar.value = value;
204+
});
205+
206+
this.eleVideo.addEventListener('play', function() {
207+
self.timerCallback();
208+
}, false);
209+
182210
this.eleVideoSource.addEventListener('error', function() {
183211
if (self.player._boolNotFound) {
184212
self.eleVideo.setAttribute('poster', self.player._notFoundPosterURL);
@@ -228,31 +256,6 @@ VideoRenderer.prototype.initPlayerControls = function() {
228256
}
229257
});
230258

231-
this.eleVideo.addEventListener('ended', function() {
232-
self._boolPlaying = false;
233-
self.updateFromDynamicState();
234-
});
235-
236-
this.eleVideo.addEventListener('pause', function() {
237-
// this is a pause that is fired from the video player itself and not from
238-
// the user clicking the play/pause button.
239-
// Noting the checkForFragmentReset function calls updateFromDynamicState
240-
self.checkForFragmentReset(self.computeFrameNumber());
241-
});
242-
243-
// Update the seek bar as the video plays
244-
this.eleVideo.addEventListener('timeupdate', function() {
245-
// Calculate the slider value
246-
const value = (100 / self.eleVideo.duration) * self.eleVideo
247-
.currentTime;
248-
// Update the slider value
249-
self.eleSeekBar.value = value;
250-
});
251-
252-
this.eleVideo.addEventListener('play', function() {
253-
self.timerCallback();
254-
}, false);
255-
256259
this.parent.addEventListener('mouseenter', function() {
257260
// Two different behaviors.
258261
// 1. Regular Mode: show controls.
@@ -360,9 +363,6 @@ VideoRenderer.prototype.updateFromDynamicState = function() {
360363
return;
361364
}
362365

363-
this.eleVideo.toggleAttribute('autoplay', this._boolAutoplay);
364-
this.eleVideo.toggleAttribute('loop', this._boolLoop);
365-
366366
if (this._boolPlaying) {
367367
if (!this._boolSingleFrame) {
368368
this.eleVideo.play();
@@ -423,6 +423,7 @@ VideoRenderer.prototype.updateStateFromTimeChange = function() {
423423
// check if we have a media fragment and should be looping
424424
// if so, reset the playing location appropriately
425425
cfn = this.checkForFragmentReset(cfn);
426+
this.updateFromDynamicState();
426427
if (cfn !== this._frameNumber) {
427428
this._frameNumber = cfn;
428429
this.processFrame();
@@ -451,6 +452,7 @@ isDataLoaded: ${this._isDataLoaded}
451452
overlayCanBePrepared: ${this._overlayCanBePrepared}
452453
isOverlayPrepared: ${this._isOverlayPrepared}
453454
isPreparingOverlay: ${this._isPreparingOverlay}
455+
hasMediaFragment: ${this._hasMediaFragment}
454456
`;
455457
};
456458

@@ -574,16 +576,13 @@ VideoRenderer.prototype.checkForFragmentReset = function(fn) {
574576
return fn;
575577
}
576578

577-
if (fn >= this._mfEndF) {
579+
if (fn >= this._mfEndF || this.eleVideo.ended) {
578580
if (this._boolLoop) {
579581
this.eleVideo.currentTime = this._mfBeginT;
580582
fn = this._mfBeginF;
581583
} else {
582584
this._boolPlaying = false;
583585
}
584-
// Important to only update in here since this is only the case that the
585-
// state has changed.
586-
this.updateFromDynamicState();
587586
}
588587

589588
return fn;

src/js/videoplayer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ VideoPlayer.prototype.autoplay = function(boolAutoplay = true) {
9999
* @return {bool} true if reset happens
100100
*/
101101
VideoPlayer.prototype.resetToFragment = function() {
102-
if (!this.renderer._hasMediaFragment) {
102+
if (!this.renderer._hasMediaFragment || !this.renderer._isRendered) {
103103
return false;
104104
}
105-
106105
this.renderer.eleVideo.currentTime = this.renderer._mfBeginT;
107106
this.renderer._lockToMF = true;
108107

test/emptylabels.html

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Player51 Empty Labels Test</title>
5+
<style>
6+
body {
7+
background: black;
8+
color:#CCCCCC;
9+
}
10+
#test-container {
11+
width: 640px;
12+
height: 360px;
13+
position: relative;
14+
}
15+
16+
#test-container:hover {
17+
opacity: .9;
18+
}
19+
</style>
20+
<link rel="stylesheet" href="/src/css/player51.css">
21+
</head>
22+
23+
<body>
24+
25+
<h1> Player51: Empty Labels Test</h1>
26+
27+
<div id="test-container" />
28+
29+
<script type="module">
30+
import Player51 from '/src/js/player51.js';
31+
32+
document.addEventListener("DOMContentLoaded", () => {
33+
console.log("Player51 Simple: Example code running.");
34+
35+
let player = new Player51(
36+
{
37+
src: "/test/player51-test-data/8Xxvx8V-hnc-001.mp4",
38+
type: "video/mp4"
39+
},
40+
"/test/player51-test-data/empty.json",
41+
25
42+
);
43+
44+
console.log("Player51 created.");
45+
46+
player.render('test-container');
47+
48+
console.log("Player51 rendered and ready.");
49+
50+
});
51+
</script>
52+
</body>
53+
</html>

test/endOfClipLooping.html

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Player51 End of Clip Test</title>
5+
<style>
6+
body {
7+
background: black;
8+
color:#CCCCCC;
9+
}
10+
#test-container {
11+
width: 640px;
12+
height: 360px;
13+
position: relative;
14+
padding: 2rem;
15+
}
16+
</style>
17+
<link rel="stylesheet" href="/src/css/player51.css">
18+
</head>
19+
20+
<body>
21+
22+
<h1> Player51: End of Clip Test </h1>
23+
24+
<div id="test-container" />
25+
26+
<script type="module">
27+
import Player51 from '/src/js/player51.js';
28+
29+
document.addEventListener("DOMContentLoaded", () => {
30+
console.log("Player51 Simple: Example code running.");
31+
32+
let player = new Player51(
33+
{
34+
src: "/test/player51-test-data/8Xxvx8V-hnc-001.mp4#t=58,61.5",
35+
type: "video/mp4"
36+
},
37+
"/test/player51-test-data/8Xxvx8V-hnc-001.json",
38+
25
39+
);
40+
41+
console.log("Player51 created.");
42+
43+
player.setBoolDrawFrameNumber(true);
44+
player.setBoolDrawTimeStamp(true);
45+
player.loop();
46+
player.autoplay();
47+
player.resetToFragment();
48+
49+
player.poster("https://voxel51.com/images/logo/voxel51-logo-horz-color-600dpi.png");
50+
player.forceMax(); // uncomment and video will maximize to pixel resolution
51+
player.render('test-container');
52+
53+
console.log("Player51 rendered and ready.");
54+
55+
});
56+
</script>
57+
</body>
58+
</html>

0 commit comments

Comments
 (0)