6

I am currently working on DASH player using JavaScript and MediaSource API

Streaming is working fine but I am stuck with changing representation. Probably the most bruteforced way to change representation during playback is about replacing <video> element in HTML document.

Hovewer, I was wondering if there is a simple way to implement adaptation (changing representation) with Media Source API. I've read that single Media Source object can handle many source buffers, but after adding second video buffer an exception is raised.

I am using Chrome 43.0.2357.65m

var mediaSource = MediaSource();
var url = URL.createObjectURL(mediaSource);

videoElement.src = url;

mediaSource.addEventListener('sourceopen', function () {
    var buffer1 = mediaSource.addSourceBuffer('video/mp4; codecs="avc1.4d4015"');
    var buffer2 = mediaSource.addSourceBuffer('video/mp4; codecs="avc1.4d4015"');
}

Exception:

Uncaught QuotaExceededError: Failed to execute 'addSourceBuffer' on    'MediaSource': This MediaSource has reached the limit of SourceBuffer objects it can handle. No additional SourceBuffer objects may be added.
4

1 回答 1

6

不幸的是,MSE 规范并没有对平滑更改表示进行太多说明。学习如何做到这一点的方法是阅读现有破折号播放器的代码,看看它是如何做到的。为了节省您大量的时间,这里是如何做到这一点:

  1. 首先,您只需要一个源缓冲区。不同表示的编解码器不同并不重要。您创建一个源缓冲区并在播放器的整个生命周期中使用它。切换表示多少次都没关系。

  2. 切换表示的方式其实很简单。您只需要将目标表示的初始化标头附加到源缓冲区。就是这样。之后,解码器已重新初始化,您可以开始附加属于新表示的段。

  3. 附加目标表示的片段并享受平滑过渡。

就这样。一旦你弄清楚你必须做什么,这并不难。

于 2015-06-08T09:36:44.687 回答