-
Notifications
You must be signed in to change notification settings - Fork 113
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: Retain quality setting when setting/switching audio tracks #720
Changes from all commits
0530593
c64d23b
837502b
4f7ebaa
e5eb4d5
3a9f0d6
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 |
---|---|---|
|
@@ -29,6 +29,7 @@ class DashViewer extends VideoBaseViewer { | |
this.loadeddataHandler = this.loadeddataHandler.bind(this); | ||
this.adaptationHandler = this.adaptationHandler.bind(this); | ||
this.shakaErrorHandler = this.shakaErrorHandler.bind(this); | ||
this.shakaManifestLoadedHandler = this.shakaManifestLoadedHandler.bind(this); | ||
this.requestFilter = this.requestFilter.bind(this); | ||
this.handleQuality = this.handleQuality.bind(this); | ||
this.handleSubtitle = this.handleSubtitle.bind(this); | ||
|
@@ -152,10 +153,11 @@ class DashViewer extends VideoBaseViewer { | |
this.adapting = true; | ||
this.player = new shaka.Player(this.mediaEl); | ||
this.player.addEventListener('adaptation', this.adaptationHandler); | ||
this.player.addEventListener('streaming', this.shakaManifestLoadedHandler); | ||
this.player.addEventListener('error', this.shakaErrorHandler); | ||
this.player.configure({ | ||
abr: { | ||
enabled: true | ||
enabled: false | ||
}, | ||
streaming: { | ||
bufferingGoal: MAX_BUFFER, | ||
|
@@ -239,6 +241,25 @@ class DashViewer extends VideoBaseViewer { | |
} | ||
} | ||
|
||
/** | ||
* Given a an audio ID (e.g. english track audio ID), enables the track with that audio ID | ||
* while maintaining the SAME VIDEO as the active track. | ||
* | ||
* @private | ||
* @param {number} role - The role of the audio used in the variant (provided by Shaka) | ||
* @return {void} | ||
*/ | ||
enableAudioId(role) { | ||
const tracks = this.player.getVariantTracks(); | ||
const activeTrack = this.getActiveTrack(); | ||
// We select a track that has the desired audio role but maintains the same video ID as our currently active track. | ||
const newTrack = tracks.find((track) => track.roles[0] === role && track.videoId === activeTrack.videoId); | ||
if (newTrack && newTrack.audioId !== activeTrack.audioId) { | ||
this.showLoadingIcon(newTrack.id); | ||
this.player.selectVariantTrack(newTrack, true); | ||
} | ||
} | ||
|
||
/** | ||
* Enables or disables automatic adaptation | ||
* | ||
|
@@ -280,9 +301,9 @@ class DashViewer extends VideoBaseViewer { | |
*/ | ||
handleAudioTrack() { | ||
const audioIdx = parseInt(this.cache.get('media-audiotracks'), 10); | ||
if (this.audioTracks[audioIdx] !== undefined) { | ||
const track = this.audioTracks[audioIdx]; | ||
this.player.selectAudioLanguage(track.language, track.role); | ||
const newAudioTrack = this.audioTracks[audioIdx]; | ||
if (newAudioTrack !== undefined) { | ||
this.enableAudioId(newAudioTrack.role); | ||
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. This'll throw an error if 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. this is how we build the audio tracks
We make this assumption that tracks coming back from the manifest are objects all over the code. Should I trust this as a fact or add the check everywhere else? 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. Dang, I gotcha. So if there can only ever be |
||
} | ||
} | ||
|
||
|
@@ -387,6 +408,25 @@ class DashViewer extends VideoBaseViewer { | |
} | ||
} | ||
|
||
/** | ||
* Handles streaming event which is the first time the manifest is available. See https://shaka-player-demo.appspot.com/docs/api/shaka.Player.html#event:StreamingEvent | ||
* | ||
* @private | ||
* @param {Object} shakaError - Error to handle | ||
* @return {void} | ||
*/ | ||
shakaManifestLoadedHandler() { | ||
this.calculateVideoDimensions(); | ||
this.loadUI(); | ||
|
||
if (this.hdVideoId !== -1) { | ||
this.mediaControls.enableHDSettings(); | ||
} | ||
|
||
this.loadSubtitles(); | ||
this.loadAlternateAudio(); | ||
} | ||
|
||
/** | ||
* Adds event listeners to the media controls. | ||
* Makes changes to the media element. | ||
|
@@ -463,15 +503,10 @@ class DashViewer extends VideoBaseViewer { | |
this.autoplay(); | ||
} | ||
|
||
this.calculateVideoDimensions(); | ||
this.loadUI(); | ||
this.loadFilmStrip(); | ||
this.resize(); | ||
this.handleVolume(); | ||
this.startBandwidthTracking(); | ||
this.handleQuality(); // should come after gettings rep ids | ||
this.loadSubtitles(); | ||
this.loadAlternateAudio(); | ||
this.showPlayButton(); | ||
|
||
this.loaded = true; | ||
|
@@ -483,17 +518,6 @@ class DashViewer extends VideoBaseViewer { | |
this.mediaContainerEl.focus(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
loadUI() { | ||
super.loadUI(); | ||
|
||
if (this.hdVideoId !== -1) { | ||
this.mediaControls.enableHDSettings(); | ||
} | ||
} | ||
|
||
/** | ||
* Loads the film strip | ||
* | ||
|
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.
Setting this to false by default, it will get overridden if 'auto' is saved in our cache as the current quality setting.