Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix replay functionality #204

Merged
merged 6 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/middleware-set-current-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import videojs from 'video.js';
// since VHS handles HLS and DASH (and in the future, more types), use * to capture all
videojs.use('*', (player) => {
return {
setSource: (srcObj, next) => {
setSource(srcObj, next) {
// pass null as the first argument to indicate that the source is not rejected
next(null, srcObj);
},
Expand All @@ -12,12 +12,24 @@ videojs.use('*', (player) => {
// level), this middleware will capture the action. For internal seeks (generated at
// the tech level), we use a wrapped function so that we can handle it on our own
// (specified elsewhere).
setCurrentTime: (time) => {
if (player.vhs && player.currentSource().src === player.vhs.source_.src) {
setCurrentTime(time) {
if (player.vhs &&
player.currentSource().src === player.vhs.source_.src) {
player.vhs.setCurrentTime(time);
}

return time;
},

// Sync VHS after play requests.
// This specifically handles replay where the order of actions is
// play, video element will seek to 0 (skipping the setCurrentTime middleware)
// then triggers a play event.
play() {
if (player.vhs &&
player.currentSource().src === player.vhs.source_.src) {
player.vhs.setCurrentTime(player.currentTime());
}
}
};
});
42 changes: 32 additions & 10 deletions test/playback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ QUnit.module('Playback', {
video.width = 600;
video.height = 300;
this.fixture.appendChild(video);
this.player = videojs(video, { muted: true });
this.player = videojs(video, {
muted: true,
autoplay: true
});
this.player.ready(done);
},
afterEach() {
Expand All @@ -44,8 +47,6 @@ QUnit.test('Advanced Bip Bop', function(assert) {
assert.expect(2);
let player = this.player;

player.autoplay(true);

playFor(player, 2, function() {
assert.ok(true, 'played for at least two seconds');
assert.equal(player.error(), null, 'has no player errors');
Expand All @@ -59,13 +60,39 @@ QUnit.test('Advanced Bip Bop', function(assert) {
});
});

QUnit.skip('playlist with fmp4 and ts segments', function(assert) {
QUnit.test('replay', function(assert) {
let done = assert.async();

assert.expect(2);
let player = this.player;

player.autoplay(true);
// seek to near the end of the video
playFor(player, 1, function() {
player.currentTime(player.duration() - 1);
});

player.one('ended', function() {
player.one('timeupdate', function() {
assert.ok(player.currentTime() < 10, 'played');
assert.equal(player.error(), null, 'has no player errors');

done();
});

player.play();
});

player.src({
src: 'http://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8',
type: 'application/x-mpegURL'
});
});

QUnit.skip('playlist with fmp4 and ts segments', function(assert) {
let done = assert.async();

assert.expect(2);
let player = this.player;

playFor(player, 6, function() {
assert.ok(true, 'played for at least six seconds to hit the change in container format');
Expand All @@ -86,7 +113,6 @@ QUnit.test('Advanced Bip Bop preload=none', function(assert) {
assert.expect(2);
let player = this.player;

player.autoplay(true);
player.preload('none');

playFor(player, 2, function() {
Expand All @@ -108,8 +134,6 @@ QUnit.test('Big Buck Bunny', function(assert) {
assert.expect(2);
let player = this.player;

player.autoplay(true);

playFor(player, 2, function() {
assert.ok(true, 'played for at least two seconds');
assert.equal(player.error(), null, 'has no player errors');
Expand All @@ -129,8 +153,6 @@ QUnit.test('Live DASH', function(assert) {
assert.expect(2);
let player = this.player;

player.autoplay(true);

playFor(player, 2, function() {
assert.ok(true, 'played for at least two seconds');
assert.equal(player.error(), null, 'has no player errors');
Expand Down