Skip to content

Commit dce4a2c

Browse files
brandonocaseygkatsev
authored andcommitted
fix(liveui): make edge detection less strict, add docs for option (videojs#5661)
Use double the seekable increment for live edge detection. Add liveui option.
1 parent 98b4a1c commit dce4a2c

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

docs/guides/options.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,18 @@ Learn more about [languages in Video.js][languages]
247247

248248
> **Note**: Generally, this option is not needed and it would be better to pass your custom languages to `videojs.addLanguage()`, so they are available in all players!
249249
250+
### `liveui`
251+
252+
> Type: `boolean`
253+
> Default: `false`
254+
255+
Allows the player to use the new live ui that includes:
256+
* A progress bar for seeking within the live window
257+
* A button that can be clicked to seek to the live edge with a circle indicating if you are at the live edge or not.
258+
259+
Without this option the progress bar will be hidden and in its place will be text that indicates `LIVE` playback. There will be no progress control
260+
and you will not be able click the text to seek to the live edge. `liveui` will default to `true` in a future version!
261+
250262
### `nativeControlsForTouch`
251263

252264
> Type: `boolean`

src/js/live-tracker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class LiveTracker extends Component {
2828
// that a player can be, but still be considered live.
2929
// we add 0.07 because the live tracking happens every 30ms
3030
// and we want some wiggle room for short segment live playback
31-
const liveEdgeWindow = seekableIncrement + 0.07;
31+
const liveEdgeWindow = (seekableIncrement * 2) + 0.07;
3232

3333
// on Android liveCurrentTime can bee Infinity, because seekableEnd
3434
// can be Infinity, so we handle that case.

test/unit/live-tracker.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ QUnit.module('LiveTracker', () => {
6666
});
6767

6868
QUnit.test('Triggers liveedgechange when we fall behind and catch up', function(assert) {
69+
70+
this.liveTracker.seekableIncrement_ = 6;
6971
this.player.trigger('timeupdate');
7072
this.player.currentTime = () => 0;
7173
this.clock.tick(20000);
@@ -107,7 +109,7 @@ QUnit.module('LiveTracker', () => {
107109
return 0;
108110
};
109111

110-
this.clock.tick(3000);
112+
this.clock.tick(6000);
111113

112114
assert.ok(this.liveTracker.pastSeekEnd() > 2, 'pastSeekEnd should be over 2s');
113115

@@ -154,15 +156,15 @@ QUnit.module('LiveTracker', () => {
154156
QUnit.test('single seekable, helpers should be correct', function(assert) {
155157
// simple
156158
this.player.seekable = () => createTimeRanges(10, 50);
157-
assert.strictEqual(this.liveTracker.liveWindow(), 40.03, 'liveWindow is 40s');
159+
assert.strictEqual(Math.round(this.liveTracker.liveWindow()), 40, 'liveWindow is ~40s');
158160
assert.strictEqual(this.liveTracker.seekableStart(), 10, 'seekableStart is 10s');
159161
assert.strictEqual(this.liveTracker.seekableEnd(), 50, 'seekableEnd is 50s');
160162
});
161163

162164
QUnit.test('multiple seekables, helpers should be correct', function(assert) {
163165
// multiple
164166
this.player.seekable = () => createTimeRanges([[0, 1], [2, 3], [4, 5]]);
165-
assert.strictEqual(this.liveTracker.liveWindow(), 5.03, 'liveWindow is 5s');
167+
assert.strictEqual(Math.round(this.liveTracker.liveWindow()), 5, 'liveWindow is ~5s');
166168
assert.strictEqual(this.liveTracker.seekableStart(), 0, 'seekableStart is 0s');
167169
assert.strictEqual(this.liveTracker.seekableEnd(), 5, 'seekableEnd is 5s');
168170
});

0 commit comments

Comments
 (0)