无法使用媒体源extension.API播放.aac扩展音频文件

时间:2019-06-23 15:09:46

标签: audio mime-types html5-audio aac media-source

我想使用MEdia源扩展名播放.aac音频文件。我将示例代码替换为mime =“ audio / aac”,并使用了.aac文件。还有其他需要指定的参数吗?

var vidElement = document.querySelector('audio');

if (window.MediaSource) {
  var mediaSource = new MediaSource();
  vidElement.src = URL.createObjectURL(mediaSource);
  mediaSource.addEventListener('sourceopen', sourceOpen);
} else {
  console.log("The Media Source Extensions API is not supported.")
}

function sourceOpen(e) {
  URL.revokeObjectURL(vidElement.src);
  var mime = 'audio/aac';
  var mediaSource = e.target;
  var sourceBuffer = mediaSource.addSourceBuffer(mime);
  var videoUrl = 'example.aac';
  fetch(videoUrl)
    .then(function(response) {
      return response.arrayBuffer();
    })
    .then(function(arrayBuffer) {
      sourceBuffer.addEventListener('updateend', function(e) {
        if (!sourceBuffer.updating && mediaSource.readyState === 'open') {
          mediaSource.endOfStream();
        }
      });
      sourceBuffer.appendBuffer(arrayBuffer);
    });
}

0 个答案:

没有答案