This repository has been archived by the owner on Jan 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 794
fix InvalidStateError for live playback in IE11 #1266
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -698,17 +698,41 @@ export class MasterPlaylistController extends videojs.EventTarget { | |
// 3) the player has not started playing | ||
!this.hasPlayed_()) { | ||
|
||
let setHasPlayed = false; | ||
|
||
// when the video is a live stream | ||
if (!media.endList) { | ||
this.trigger('firstplay'); | ||
|
||
// seek to the latest media position for live videos | ||
seekable = this.seekable(); | ||
if (seekable.length) { | ||
this.tech_.setCurrentTime(seekable.end(0)); | ||
if (videojs.browser.IE_VERSION && | ||
this.mode_ === 'html5' && | ||
this.tech_.readyState() === 0) { | ||
// IE11 throws an InvalidStateError if you try to set currentTime while the | ||
// readyState is 0, so it must be delayed. | ||
this.tech_.one('loadedmetadata', () => { | ||
// we hold off on setting hasPlayed on true until after we seek to prevent | ||
// segment loaders from requesting more than 1 segment before the seek to | ||
// live point | ||
this.tech_.setCurrentTime(seekable.end(0)); | ||
this.hasPlayed_ = () => true; | ||
}); | ||
} else { | ||
setHasPlayed = true; | ||
this.tech_.setCurrentTime(seekable.end(0)); | ||
} | ||
} | ||
} else { | ||
// always set hasPlayed to true for first play of VOD | ||
setHasPlayed = true; | ||
} | ||
this.hasPlayed_ = () => true; | ||
|
||
if (setHasPlayed) { | ||
this.hasPlayed_ = () => true; | ||
} | ||
|
||
// now that we are ready, load the segment | ||
this.load(); | ||
return true; | ||
|
@@ -893,14 +917,9 @@ export class MasterPlaylistController extends videojs.EventTarget { | |
} | ||
|
||
// In flash playback, the segment loaders should be reset on every seek, even | ||
// in buffer seeks | ||
const isFlash = | ||
(this.mode_ === 'flash') || | ||
(this.mode_ === 'auto' && !videojs.MediaSource.supportsNativeMediaSources()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I snuck this change into this PR because the mode can only be |
||
|
||
// if the seek location is already buffered, continue buffering as | ||
// in buffer seeks. If the seek location is already buffered, continue buffering as | ||
// usual | ||
if (buffered && buffered.length && !isFlash) { | ||
if (buffered && buffered.length && this.mode_ !== 'flash') { | ||
return currentTime; | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this set here, and not where hasPlayed_ is set? You could move this into the loadedmetadata function above, and set it on line 733 as well.
I'm mostly suggesting this because I think it will be easier from a maintenance standpoint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow. This function
setupFirstPlay
is called whenplay
is triggered untilthis.hasPlayed_()
returnstrue
. Currently, with a VOD, we updatehasPlayed_
to return true the first time we get aplay
call and we've loaded the media. Currently in a live stream, we updatehasPlayed_
to true the first time we get aplay
call, we've loaded the media, and have calculated seekable, so that we can seek to the live point and that segmentloader knows it can start filling the buffer. Since now we have to wait forloadedmetadata
from the tech in IE11 before we can seek, we wait to updatehasPlayed_
until we've gottenloadedmetadata
which happens after we append the first bytes to the source buffer. Since this is asynchronous, this local varsetHasPlayed
is used to know if we can sethasPlayed_
to true yet. Does this answer your question?