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: user can pick variant track/texttrack from streaming event #3459

Merged
merged 4 commits into from
Jul 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 43 additions & 25 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1866,34 +1866,56 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
this.dispatchEvent(this.makeEvent_(shaka.Player.EventName.Streaming));

// Pick the initial streams to play.
kocoten1992 marked this conversation as resolved.
Show resolved Hide resolved
const initialVariant = this.chooseVariant_();
goog.asserts.assert(initialVariant, 'Must choose an initial variant!');
this.switchVariant_(initialVariant, /* fromAdaptation= */ true,
/* clearBuffer= */ false, /* safeMargin= */ 0);
// however, we would skip switch to initial variant
// if user already pick variant track (via selectVariantTrack api)
let initialVariant = null;
const activeVariantTrack = this.getVariantTracks().find((t) => t.active);

if (!activeVariantTrack) {
kocoten1992 marked this conversation as resolved.
Show resolved Hide resolved
initialVariant = this.chooseVariant_();
goog.asserts.assert(initialVariant, 'Must choose an initial variant!');
this.switchVariant_(initialVariant, /* fromAdaptation= */ true,
/* clearBuffer= */ false, /* safeMargin= */ 0);

// Now that we have initial streams, we may adjust the start time to align
// to a segment boundary.
if (this.config_.streaming.startAtSegmentBoundary) {
const startTime = this.playhead_.getTime();
const adjustedTime =
await this.adjustStartTime_(initialVariant, startTime);

this.playhead_.setStartTime(adjustedTime);
}

// Decide if text should be shown automatically.
const initialTextStream = this.chooseTextStream_();
if (initialTextStream) {
this.addTextStreamToSwitchHistory_(
initialTextStream, /* fromAdaptation= */ true);
// Since the first streams just became active, send an adaptation event.
this.onAdaptation_(null,
shaka.util.StreamUtils.variantToTrack(initialVariant));
}

this.setInitialTextState_(initialVariant, initialTextStream);
// Don't initialize with a text stream unless we should be streaming text.
if (initialTextStream && this.shouldStreamText_()) {
this.streamingEngine_.switchTextStream(initialTextStream);
}
// Decide if text should be shown automatically.
// similar to video/audio track, we would skip switch initial text track
// if user already pick text track (via selectTextTrack api)
const activeTextTrack = this.getTextTracks().find((t) => t.active);

// Now that we have initial streams, we may adjust the start time to align
// to a segment boundary.
if (this.config_.streaming.startAtSegmentBoundary) {
const startTime = this.playhead_.getTime();
const adjustedTime =
await this.adjustStartTime_(initialVariant, startTime);
if (!activeTextTrack) {
const initialTextStream = this.chooseTextStream_();

this.playhead_.setStartTime(adjustedTime);
if (initialTextStream) {
this.addTextStreamToSwitchHistory_(
initialTextStream, /* fromAdaptation= */ true);
}

if (initialVariant) {
this.setInitialTextState_(initialVariant, initialTextStream);
}

// Don't initialize with a text stream unless we should be streaming text.
if (initialTextStream && this.shouldStreamText_()) {
this.streamingEngine_.switchTextStream(initialTextStream);
}
}


// Start streaming content. This will start the flow of content down to
// media source.
await this.streamingEngine_.start();
Expand All @@ -1908,10 +1930,6 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
// Dispatch a 'trackschanged' event now that all initial filtering is done.
this.onTracksChanged_();

// Since the first streams just became active, send an adaptation event.
this.onAdaptation_(null,
shaka.util.StreamUtils.variantToTrack(initialVariant));

// Now that we've filtered out variants that aren't compatible with the
// active one, update abr manager with filtered variants.
// NOTE: This may be unnecessary. We've already chosen one codec in
Expand Down