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

fix: fix replay functionality #204

merged 6 commits into from
Aug 24, 2018

Conversation

forbesjo
Copy link
Contributor

@forbesjo forbesjo commented Aug 24, 2018

Description

Fixes #201

Specific Changes proposed

Replay is broken because VHS is not loading the buffer when the video element seeks on replay. This previously worked because VHS would react to video element seek events. The seek caused by replay does not call player.currentTime() so the middleware does not kick in. This adds an additional middleware to call VHS's during play calls.

Previously the play method of VHS would not go down the ended -> seek to 0 path because the tech would have already seeked to 0 on it's own, then emitted a play event.

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
  • Reviewed by Two Core Contributors

play() {
if (player.vhs &&
player.currentSource().src === player.vhs.source_.src) {
player.vhs.setCurrentTime(player.currentTime());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is meant to be a short-term fix, but we should add some comments about what we're doing and why it works for the replay case.


player.one('ended', function() {
player.one('timeupdate', function() {
assert.ok(true, 'played');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth checking the currentTime here.

@forbesjo
Copy link
Contributor Author

Instead of calling VHS's play before the tech's play, I am syncing VHS with the player after play. This is because I had an issue with live streams where the VHS play assumes that the player is in a playing state.


// Sync VHS after play requests.
// This specifically handles replay where the video element will
// seek to 0, skipping the setCurrentTime middleware, then play
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically it plays first, but triggers the play event last

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll clarify

play() {
if (player.vhs &&
player.currentSource().src === player.vhs.source_.src) {
player.vhs.setCurrentTime(player.currentTime());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would feel better if we specifically handled the case where player.currentTime() === 0 instead of always doing this

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

player.autoplay(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have to autoplay? Seems like this would be annoying to manage with autoplay restrictions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to simplify the tests and not have to wait for loadstart before playing. Autoplay restrictions aren't a problem because the player is muted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could remove the autoplay setting from all the tests and just create the player with autoplay on

@gesinger
Copy link
Contributor

Tested in Chrome, Firefox, and IE11 (on a Windows VM).

@forbesjo forbesjo merged commit fd6be83 into master Aug 24, 2018
@forbesjo forbesjo deleted the fix-replay branch August 24, 2018 22:36
@gkatsev
Copy link
Member

gkatsev commented Aug 24, 2018

The middleware file probably should be renamed now 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replay is not working
4 participants