diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index 2039af1f3f..474192a743 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -784,13 +784,12 @@ shaka.media.MediaSourceEngine = class { * @param {?shaka.media.SegmentReference} reference The segment reference * we are appending, or null for init segments * @param {!string} mimeType - * @param {!number} timestampOffset - * @return {?number} + * @return {{timestamp: ?number, metadata: !Array.}} * @private */ - getTimestampAndDispatchMetadata_(contentType, data, reference, mimeType, - timestampOffset) { + getTimestampAndDispatchMetadata_(contentType, data, reference, mimeType) { let timestamp = null; + let metadata = []; const uint8ArrayData = shaka.util.BufferUtils.toUint8(data); if (shaka.util.MimeUtils.RAW_FORMATS.includes(mimeType)) { @@ -804,7 +803,7 @@ shaka.media.MediaSourceEngine = class { timestamp = Math.round(metadataTimestamp.data) / 1000; } /** @private {shaka.extern.ID3Metadata} */ - const metadata = { + const id3Metadata = { cueTime: reference.startTime, data: uint8ArrayData, frames: frames, @@ -812,7 +811,7 @@ shaka.media.MediaSourceEngine = class { pts: reference.startTime, }; this.playerInterface_.onMetadata( - [metadata], /* offset= */ 0, reference.endTime); + [id3Metadata], /* offset= */ 0, reference.endTime); } } else if (mimeType.includes('/mp4') && reference && reference.timestampOffset == 0 && @@ -852,13 +851,9 @@ shaka.media.MediaSourceEngine = class { if (startTime != null) { timestamp = startTime; } - const metadata = tsParser.getMetadata(); - if (metadata.length) { - this.playerInterface_.onMetadata(metadata, timestampOffset, - reference ? reference.endTime : null); - } + metadata = tsParser.getMetadata(); } - return timestamp; + return {timestamp, metadata}; } /** @@ -922,8 +917,8 @@ shaka.media.MediaSourceEngine = class { mimeType = this.transmuxers_[contentType].getOriginalMimeType(); } if (reference) { - const timestamp = this.getTimestampAndDispatchMetadata_( - contentType, data, reference, mimeType, timestampOffset); + const {timestamp, metadata} = this.getTimestampAndDispatchMetadata_( + contentType, data, reference, mimeType); if (timestamp != null) { if (this.firstVideoTimestamp_ == null && contentType == ContentType.VIDEO) { @@ -985,6 +980,10 @@ shaka.media.MediaSourceEngine = class { this.textSequenceModeOffset_.resolve(timestampOffset); } } + if (metadata.length) { + this.playerInterface_.onMetadata(metadata, timestampOffset, + reference ? reference.endTime : null); + } } if (hasClosedCaptions && contentType == ContentType.VIDEO) { if (!this.textEngine_) {