MediaSource是Media Source Extensions API 表示媒体资源

MediaSourceMedia Source Extensions API 表示媒体资源HTMLMediaElement对象的接口。MediaSource 对象可以附着在HTMLMediaElement在客户端进行播放。

构造函数

  • MediaSource()

  • 构造并且返回一个新的MediaSource的空对象(with no associated source buffers)。

属性

从父接口EventTarget上继承而来。

      方法

      Inherits properties from its parent interface, EventTarget.

      Examples

      这个例子尽可能快地逐块加载视频,并在加载好后立刻播放。 This example was written by Nick Desaulniers and can be viewed live here (you can also download the source for further investigation.)

      var video = document.querySelector('video');var assetURL = 'frag_bunny.mp4';// Need to be specific for Blink regarding codecs// ./mp4info frag_bunny.mp4 | grep Codecvar mimeCodec = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"';if ('MediaSource' in window && MediaSource.isTypeSupported(mimeCodec)) {
        var mediaSource = new MediaSource();
        //console.log(mediaSource.readyState); // closed
        video.src = URL.createObjectURL(mediaSource);
        mediaSource.addEventListener('sourceopen', sourceOpen);} else {
        console.error('Unsupported MIME type or codec: ', mimeCodec);}function sourceOpen (_) {
        //console.log(this.readyState); // open
        var mediaSource = this;
        var sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
        fetchAB(assetURL, function (buf) {
          sourceBuffer.addEventListener('updateend', function (_) {
            mediaSource.endOfStream();
            video.play();
            //console.log(mediaSource.readyState); // ended
          });
          sourceBuffer.appendBuffer(buf);
        });};function fetchAB (url, cb) {
        console.log(url);
        var xhr = new XMLHttpRequest;
        xhr.open('get', url);
        xhr.responseType = 'arraybuffer';
        xhr.onload = function () {
          cb(xhr.response);
        };
        xhr.send();};

      说明

      SpecificationStatusComment
      Media Source Extensions
      MediaSource
      Candidate RecommendationInitial definition.

      浏览器支持情况  

      FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
      Basic support23-webkit
          31
      (Yes)25.0 (25.0)[1]
          42.0 (42.0)
      11[2]158

      [1] Available after switching the about:config preference media.mediasource.enabled to true.  In addition, support was limited to a whitelist of sites, for example  YouTube, Netflix, and other popular streaming sites. The whitelist was  removed and Media Source Extensions was enabled by default in 42+ for  all sites.

      [2] Only works on Windows 8+.


      上一篇:Mysql字符串字段判断是否包含某个字符串的3种方法

      下一篇:H5流式播放(FMP4转封装与mediaSource)

      评论列表
      发表评论
      称呼
      邮箱
      网址
      验证码(*)
      热评文章
      相关阅读