-
Notifications
You must be signed in to change notification settings - Fork 424
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
feat: Add support for ManagedMediaSource 'startstreaming' and 'endstream' event handling #1542
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,6 +192,7 @@ | |
this.playlistExclusionDuration = playlistExclusionDuration; | ||
this.maxPlaylistRetries = maxPlaylistRetries; | ||
this.enableLowInitialPlaylist = enableLowInitialPlaylist; | ||
this.hasManagedMediaSource_ = false; | ||
|
||
if (this.useCueTags_) { | ||
this.cueTagsTrack_ = this.tech_.addTextTrack( | ||
|
@@ -215,6 +216,8 @@ | |
// Airplay source not yet implemented. Remote playback must be disabled. | ||
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. You can change the above if statement to:
|
||
this.tech_.el_.disableRemotePlayback = true; | ||
this.mediaSource = new window.ManagedMediaSource(); | ||
this.hasManagedMediaSource_ = true; | ||
|
||
videojs.log('Using ManagedMediaSource'); | ||
} else if (window.MediaSource) { | ||
this.mediaSource = new window.MediaSource(); | ||
|
@@ -232,6 +235,14 @@ | |
// we don't have to handle sourceclose since dispose will handle termination of | ||
// everything, and the MediaSource should not be detached without a proper disposal | ||
|
||
if (this.hasManagedMediaSource_) { | ||
this.handleStartStreaming_ = this.handleStartStreaming_.bind(this); | ||
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. You can add the content of this if statement to the above pre-existing if statement. All nits, but saves a few lines 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. You mean to the 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. Yeah, all my comments were basically to save some lines of code by moving this code to where you set the |
||
this.handleEndStreaming_ = this.handleEndStreaming_.bind(this); | ||
|
||
this.mediaSource.addEventListener('startstreaming', this.handleStartStreaming_); | ||
this.mediaSource.addEventListener('endstreaming', this.handleEndStreaming_); | ||
} | ||
|
||
this.seekable_ = createTimeRanges(); | ||
this.hasPlayed_ = false; | ||
|
||
|
@@ -1056,14 +1067,31 @@ | |
*/ | ||
load() { | ||
this.mainSegmentLoader_.load(); | ||
|
||
if (this.mediaTypes_.AUDIO.activePlaylistLoader) { | ||
this.audioSegmentLoader_.load(); | ||
} | ||
|
||
if (this.mediaTypes_.SUBTITLES.activePlaylistLoader) { | ||
this.subtitleSegmentLoader_.load(); | ||
} | ||
} | ||
|
||
/** | ||
* Call pause on our SegmentLoaders | ||
*/ | ||
pause() { | ||
this.mainSegmentLoader_.pause(); | ||
|
||
if (this.mediaTypes_.AUDIO.activePlaylistLoader) { | ||
this.audioSegmentLoader_.pause(); | ||
} | ||
|
||
if (this.mediaTypes_.SUBTITLES.activePlaylistLoader) { | ||
this.subtitleSegmentLoader_.pause(); | ||
} | ||
} | ||
|
||
/** | ||
* Re-tune playback quality level for the current player | ||
* conditions. This method will perform destructive actions like removing | ||
|
@@ -1223,6 +1251,26 @@ | |
Number.MAX_VALUE : duration; | ||
} | ||
|
||
/** | ||
* Handle the startstreaming event on the ManagedMediaSource. | ||
* This event indicates that segment loading should be started/resumed. | ||
* | ||
* @private | ||
*/ | ||
handleStartStreaming_() { | ||
this.load(); | ||
} | ||
|
||
/** | ||
* Handle the endstreaming event on the ManagedMediaSource. | ||
* This event indicates that segment loading should be paused. | ||
* | ||
* @private | ||
*/ | ||
handleEndStreaming_() { | ||
this.pause(); | ||
} | ||
|
||
/** | ||
* handle the durationchange event on the MediaSource | ||
* | ||
|
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.
nit: To save a few lines of code, you could change this to:
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.
The intent of the flag was to signal that the ManagedMediaSource has been created and currently exists. If we set it here we should rename the flag to
useManagedMediaSource_
orcreateManagedMediaSource_
, as it hasn't been created yet.