/*Working with HTML5 media source extensions to play the segmented video (segmented by mp4box). It is working fine in Firefox(version 50) but in google chrome (version 53) it is displaying error.
使用HTML5媒体源扩展来播放分段视频(按mp4box分段)。它在Firefox(版本50)中运行良好,但在谷歌浏览器(版本53)中显示错误。
重现步骤:使用mp4box将1分钟.mp4视频分割为20秒段。
命令是---> mp4box -dash 20000 -segment-name segment_ myvideo.mp4
在代码中仅使用一个段。在firefox 20秒完美播放,但在谷歌Chrome中它没有播放
here is the code */
<pre>
<video id="v" autoplay controls > </video>
<script>
var segments=["segment_init.mp4","segment_1.m4s"];
var video= document.getElementById("v")
var mediaSource = new MediaSource();
video.src= URL.createObjectURL(mediaSource);
var sourceBuffer;
mediaSource.addEventListener("sourceopen",onSourceOpen);
function onSourceOpen()
{
dowloadSegment(segments[0],function(buffer) {
sourceBuffer = mediaSource.addSourceBuffer(codec) // mp4
sourceBuffer.appendBuffer(buffer);
addSegment(1);// adding first segment
});
}
function addSegment(segid)
{
dowloadSegment(segments[segid],function(buffer) {
sourceBuffer.appendBuffer(buffer);
});
}
function dowloadSegment(url,callback)
{
//here getting xmlhhtprequest response
callback(response) ;// segment data
}
</script>
</pre>