diff --git a/lib/media/transmuxer.js b/lib/media/transmuxer.js index 5119c2e255..c6c64c5665 100644 --- a/lib/media/transmuxer.js +++ b/lib/media/transmuxer.js @@ -29,9 +29,7 @@ shaka.media.Transmuxer = class { this.muxjs_ = shaka.dependencies.muxjs(); /** @private {muxjs.mp4.Transmuxer} */ - this.muxTransmuxer_ = new this.muxjs_.mp4.Transmuxer({ - 'keepOriginalTimestamps': true, - }); + this.muxTransmuxer_ = null; /** @private {shaka.util.PublicPromise} */ this.transmuxPromise_ = null; @@ -48,16 +46,22 @@ shaka.media.Transmuxer = class { /** @private {boolean} */ this.isTransmuxing_ = false; - this.muxTransmuxer_.on('data', (segment) => this.onTransmuxed_(segment)); - - this.muxTransmuxer_.on('done', () => this.onTransmuxDone_()); + if (this.muxjs_) { + this.muxTransmuxer_ = new this.muxjs_.mp4.Transmuxer({ + 'keepOriginalTimestamps': true, + }); + this.muxTransmuxer_.on('data', (segment) => this.onTransmuxed_(segment)); + this.muxTransmuxer_.on('done', () => this.onTransmuxDone_()); + } } /** * @override */ destroy() { - this.muxTransmuxer_.dispose(); + if (this.muxTransmuxer_) { + this.muxTransmuxer_.dispose(); + } this.muxTransmuxer_ = null; return Promise.resolve(); } @@ -156,6 +160,8 @@ shaka.media.Transmuxer = class { * metadata: !Array.}>} */ transmux(data) { + goog.asserts.assert(this.muxTransmuxer_, + 'mux.js should be available.'); goog.asserts.assert(!this.isTransmuxing_, 'No transmuxing should be in progress.'); this.isTransmuxing_ = true;