Skip to content

Commit

Permalink
fix: calling detatchMedia() followed by attachMedia() causes audio to…
Browse files Browse the repository at this point in the history
… not play

On re-attch the context of altAudio is not saved in buffer control so it doesn't know to create two source buffers.
Also, in context of stream controller it doesn't reset the `altAudio` flag.
I also noticed that stream controller is reloading the entire frags it has in `fragmentTracker` and it seems it needs to be reset on detach, otherwise there's a very long start delay where unncessery buffering occurs.

based on #2110 and fixes #2099.
  • Loading branch information
OrenMe committed Jul 15, 2019
1 parent 5ec8093 commit 161c66c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/controller/buffer-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class BufferController extends EventHandler {
// signals that mediaSource should have endOfStream called
private _needsEos: boolean = false;

// Track whether the parsed manifest signaled alternate audio
// private _altAudio: boolean = false;

private config: BufferControllerConfig;

// this is optional because this property is removed from the class sometimes
Expand Down Expand Up @@ -143,6 +146,7 @@ class BufferController extends EventHandler {
// sourcebuffers will be created all at once when the expected nb of tracks will be reached
// in case alt audio is not used, only one BUFFER_CODEC event will be fired from main stream controller
// it will contain the expected nb of source buffers, no need to compute it
// this._altAudio = data.altAudio;
this.bufferCodecEventsExpected = data.altAudio ? 2 : 1;
logger.log(`${this.bufferCodecEventsExpected} bufferCodec event(s) expected`);
}
Expand Down Expand Up @@ -202,6 +206,7 @@ class BufferController extends EventHandler {
this.mediaSource = null;
this.media = null;
this._objectUrl = null;
// this.bufferCodecEventsExpected = this._altAudio ? 2 : 1;
this.pendingTracks = {};
this.tracks = {};
this.sourceBuffer = {};
Expand Down
3 changes: 2 additions & 1 deletion src/controller/stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,8 @@ class StreamController extends BaseStreamController {
media.removeEventListener('ended', this.onvended);
this.onvseeking = this.onvseeked = this.onvended = null;
}
this.media = this.mediaBuffer = null;
this.fragmentTracker.removeAllFragments();
this.media = this.mediaBuffer = this.altAudio = null;
this.loadedmetadata = false;
this.stopLoad();
}
Expand Down

0 comments on commit 161c66c

Please sign in to comment.