Skip to content

Commit

Permalink
Merge pull request #2303 from video-dev/bugfix/2099
Browse files Browse the repository at this point in the history
fix: calling detatchMedia() followed by attachMedia() causes audio to not play
  • Loading branch information
robwalch committed Oct 8, 2019
2 parents 6557166 + cb263f9 commit 09797f5
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/controller/audio-stream-controller.js
Expand Up @@ -381,6 +381,7 @@ class AudioStreamController extends BaseStreamController {
}
this.media = this.mediaBuffer = this.videoBuffer = null;
this.loadedmetadata = false;
this.fragmentTracker.removeAllFragments();
this.stopLoad();
}

Expand Down
6 changes: 5 additions & 1 deletion src/controller/buffer-controller.ts
Expand Up @@ -55,6 +55,9 @@ class BufferController extends EventHandler {
// The number of BUFFER_CODEC events received before any sourceBuffers are created
public bufferCodecEventsExpected: number = 0;

// The total number of BUFFER_CODEC events received
private _bufferCodecEventsTotal: number = 0;

// A reference to the attached media element
public media: HTMLMediaElement | null = null;

Expand Down Expand Up @@ -143,7 +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.bufferCodecEventsExpected = data.altAudio ? 2 : 1;
this.bufferCodecEventsExpected = this._bufferCodecEventsTotal = data.altAudio ? 2 : 1;
logger.log(`${this.bufferCodecEventsExpected} bufferCodec event(s) expected`);
}

Expand Down Expand Up @@ -202,6 +205,7 @@ class BufferController extends EventHandler {
this.mediaSource = null;
this.media = null;
this._objectUrl = null;
this.bufferCodecEventsExpected = this._bufferCodecEventsTotal;
this.pendingTracks = {};
this.tracks = {};
this.sourceBuffer = {};
Expand Down
3 changes: 3 additions & 0 deletions src/controller/stream-controller.js
Expand Up @@ -47,6 +47,7 @@ class StreamController extends BaseStreamController {
this._state = State.STOPPED;
this.stallReported = false;
this.gapController = null;
this.altAudio = false;
}

startLoad (startPosition) {
Expand Down Expand Up @@ -691,6 +692,7 @@ class StreamController extends BaseStreamController {
media.removeEventListener('ended', this.onvended);
this.onvseeking = this.onvseeked = this.onvended = null;
}
this.fragmentTracker.removeAllFragments();
this.media = this.mediaBuffer = null;
this.loadedmetadata = false;
this.stopLoad();
Expand Down Expand Up @@ -735,6 +737,7 @@ class StreamController extends BaseStreamController {
logger.log('both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC');
}

this.altAudio = data.altAudio;
this.levels = data.levels;
this.startFragRequested = false;
let config = this.config;
Expand Down
7 changes: 6 additions & 1 deletion src/controller/subtitle-stream-controller.js
Expand Up @@ -84,6 +84,11 @@ export class SubtitleStreamController extends BaseStreamController {

onMediaDetaching () {
this.media.removeEventListener('seeking', this._onMediaSeeking);
this.fragmentTracker.removeAllFragments();
this.currentTrackId = -1;
this.tracks.forEach((track) => {
this.tracksBuffered[track.id] = [];
});
this.media = null;
this.state = State.STOPPED;
}
Expand Down Expand Up @@ -111,7 +116,7 @@ export class SubtitleStreamController extends BaseStreamController {
onSubtitleTrackSwitch (data) {
this.currentTrackId = data.id;

if (!this.tracks || this.currentTrackId === -1) {
if (!this.tracks || !this.tracks.length || this.currentTrackId === -1) {
this.clearInterval();
return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/controller/subtitle-track-controller.js
Expand Up @@ -66,6 +66,11 @@ class SubtitleTrackController extends EventHandler {
this.media.textTracks.removeEventListener('change', this.trackChangeListener);
}

if (Number.isFinite(this.subtitleTrack)) {
this.queuedDefaultTrack = this.subtitleTrack;
}

this.trackId = -1;
this.media = null;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/controller/subtitle-stream-controller.js
Expand Up @@ -61,7 +61,7 @@ describe('SubtitleStreamController', function () {
});

it('should call clearInterval if no tracks present', function () {
subtitleStreamController.tracks = null;
subtitleStreamController.tracks = [];
hls.trigger(Event.SUBTITLE_TRACK_SWITCH, {
id: 0
});
Expand Down

0 comments on commit 09797f5

Please sign in to comment.