Reputation: 815
Question How can I initialize dash.js with the correct quality before the stream is initialized?
Problem:
While setting a quality with dash.js, I get green artifacts when playback starts (see image below). Quality is set after stream initialization by responding to the STREAM_INITIALIZED
event.
Context: I am trying to create an application with a dash where the user should be able to select a playback quality. This selection is will be set by using a cookie like this: cookies.set('preferredQuality', quality.value);
, where value corresponds to either 0, 1, 2 or 3 (set in dash.js with setQualityFor and setAutoSwitchQualityFor set to false
).
Then in the logic for creating the dash instance, I listen for the STREAM_INITIALIZED
event and try to set the quality there
this.dashJsInstance.on(dashjs.MediaPlayer.events.STREAM_INITIALIZED, this.onStreamInitialized, this);
onStreamInitialized: function() {
const quality = cookies.get('preferredQuality');
if (quality !== -1) {
this.dashJsInstance.setAutoSwitchQualityFor('video', false);
this.dashJsInstance.setQualityFor('video', quality);
}
},
This results in the green artifacts shown in the image.
Upvotes: 1
Views: 1460
Reputation: 815
Not sure if this is the correct answer, but solved it by listening to the onFragmentLoaded
event. This is by no means the best answer, but it works. We implemented it by doing something like this:
onFragmentLoaded: function(e) {
if (e.request && e.request.type === 'InitializationSegment') {
const preferredQuality = quality // Preferred quality;
const currentQuality = current // Current quality;
if (currentQuality !== preferredQuality) {
this.dashJsInstance.setQualityFor('video', preferredQuality);
this.dashJsInstance.setAutoSwitchQualityFor('video', false);
}
}
},
Upvotes: 1