且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Firefox MediaSourceExtension上的mp3支持

更新时间:2023-11-10 16:34:28

好,所以我能够在从事Media Source Extension的Mozilla工程师的帮助下弄清楚.

关于MSE(媒体源扩展)的第一件事要注意的是,它不一定支持浏览器的音频元素支持的所有媒体格式.为了说明这一点,尽管Firefox在直接输入到浏览器或直接输入到音频元素时将播放mp3文件,但是如果将其输入到媒体源缓冲区中,它会播放同一mp3文件.>

现在,Firefox的MSE实施实际上支持哪种媒体格式?答案是,从Firefox 42开始,默认情况下仅支持fMP4(分段MP4).还支持webm,但默认情况下不支持,您的用户将必须通过Firefox的about:config页面手动将其打开.创建新缓冲区时用于馈送媒体源对象的fMP4 mimeType是:audio/mp4; codecs ="mp4a.40.2"

如果您想知道fMP4是什么,它是MPEG-4标准的一部分,更具体地说是第12部分的标准:使用非多路复用音频/视频的ISO基本媒体文件格式(ISOBMFF) ".如果您对更多详细信息感兴趣,请查找它.

根据我的经验,所有主流浏览器和操作系统都支持fMP4-这使fMP4成为自适应和渐进式流传输的理想格式.

HTH!

I'm looking into implementing adaptive and progressive audio streaming in the browser, with no plugins. MSE is the HTML5 API I was waiting for, available in FF 42, but it seems that the audio format support in Firefox is not there?... mp3 audio is not working when using the MSE APIs.

Here's a code snippet:

var mediaSource = new window.MediaSource();
var audioSourceBuffer;

mediaSource.addEventListener('sourceopen', function (e) {
    try {
        var mimeType = "audio/mpeg";
        audioSourceBuffer = mediaSource.addSourceBuffer(mimeType);
    } catch (e) {
        log('Exception calling addSourceBuffer', e);
        return;
    }
}

I get a NotSupportedError exception when calling addSourceBuffer.

Doesn't Firefox support mp3? from MDN list of supported formats (https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats) it implies that mp3 support should be there if the OS supports it - and the OS I am testing on (OSX) does support it.

Any help appreciated!

OK, so I was able to figure it out with the kind help of Mozilla engineers working on Media Source Extension.

The first key thing to note on MSE (Media Source Extension) is that it does not necessarily support all media formats supported by the browser's Audio Element. To illustrate this, although Firefox will play mp3 file when fed directly to the browser or directly to an Audio element, it will not play the same mp3 file if you feed it into a media source buffer.

Now, which media format are actually supported by Firefox' MSE implementation? the answer is that as of Firefox 42 only fMP4 (Fragmented MP4) is supported by default. webm is also supported, but not by default and your users will have to turn it on manually through Firefox' about:config page. The fMP4 mimeType to feed the Media Source object when creating a new buffer is: audio/mp4; codecs="mp4a.40.2"

And if you're wondering what the heck is fMP4, it is a standard which is part of the MPEG-4 standard, more specifically part 12: "ISO Base Media File Format (ISOBMFF) using non-multiplexed audio/video". Look it up if you're interested in more details.

From my experience fMP4 is supported across all major browsers and OS - which makes fMP4 a good format candidate for adaptive and progressive streaming.

HTH!