diff --git a/lib/transmuxer/muxjs_transmuxer.js b/lib/transmuxer/muxjs_transmuxer.js index ebb56b4722..1feee6f695 100644 --- a/lib/transmuxer/muxjs_transmuxer.js +++ b/lib/transmuxer/muxjs_transmuxer.js @@ -33,9 +33,7 @@ shaka.transmuxer.MuxjsTransmuxer = 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; @@ -46,9 +44,13 @@ shaka.transmuxer.MuxjsTransmuxer = 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_()); + } } @@ -57,7 +59,9 @@ shaka.transmuxer.MuxjsTransmuxer = class { * @export */ destroy() { - this.muxTransmuxer_.dispose(); + if (this.muxTransmuxer_) { + this.muxTransmuxer_.dispose(); + } this.muxTransmuxer_ = null; } @@ -207,6 +211,8 @@ shaka.transmuxer.MuxjsTransmuxer = class { * @export */ 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;