Shadow
Shadow

Reputation: 4763

MediaSource appendBuffer at different positions

I am trying to use MediaSource to play two individual streams (audio and video). I have been successful with appending their buffers (ArrayBuffer type retrieved via XHR) in sequence of any size:

The video and audio play perfectly and in sync, all the ranges are correctly translated. For these tests I am using a YouTube encoded video from my collection, webm format and vp9 codec.

However the problem comes with the seeking scenario in which the player is seeked ahead of loaded segments and I want to load them from that point or near behind that point onward, without this new segment being in sequence with any previously appended buffer.

I tried the obvious idea of simply assuming that the MediaSource would recognize the segment position into which the new buffer should be appended so my attempts were just fetch the stream data related to the seeked time interval and append it to the buffer, but it does not work and the following error occurs:

Uncaught InvalidStateError: Failed to execute 'appendBuffer' on 'SourceBuffer':
The HTMLMediaElement.error attribute is not null.

I have been trying to find a solution for this, tried timestampOffset and appendWindowStart + appendWindowEnd to no avail.

I cannot find in the documentation how I can append a buffer into a position other than the sequential order, I would appreciate any help and if possible a small explanation of the process itself.

Upvotes: 4

Views: 2234

Answers (1)

Shadow
Shadow

Reputation: 4763

It seems like what I wanted to do is possible, but not the way I was doing it. Correctly encoded files for DASH streaming should contain SIDX (segment index box) information, this is basically video segment details that are present inside the videos (or audio) themselves at the start/header of the files, or listed in an independent .mpd file with xml format. Each of these segments contains the correct information that allows MSE (MediaSource extension) to play appended segments which are not linked to a previously appended buffer.

Upvotes: 3

Related Questions