How do i append two video files data to a source buffer using media source api?

后端 未结 4 563
闹比i
闹比i 2020-12-24 09:16

I have two videos name v11.webm and v12.webm.

What i want is that these two videos should run seamlessly without any gap.

I am following the media source a

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 09:50

    Just set the sourceBuffer's mode to 'sequence' (default seems to be 'segments')

    From the doc: https://developer.mozilla.org/en-US/docs/Web/API/SourceBuffer/mode

    sequence: The order in which the segments are appended to the SourceBuffer determines the order in which they are played. Segment timestamps are generated automatically for the segments that observe this order.

    In my app, I just set it after adding the the source buffer to the media source:

    // Create media source for the stream, and create the source buffer when ready
    let self = this;
    this._mediaSource = new MediaSource();
    this._mediaSource.addEventListener('sourceopen', function () {
      self._sourceBuffer = self.mediaSource.addSourceBuffer(environment.recordingMimeType);
      self._sourceBuffer.mode = 'sequence'; // This is the relevant part
      self._sourceBuffer.addEventListener('error', function (ev) {
        console.error("Source buffer error ??");
        console.error(ev);
      });
    });
    

提交回复
热议问题