向后和跨浏览器兼容的音频播放 [英] Backwards and cross-browser compatible audio playing

查看:27
本文介绍了向后和跨浏览器兼容的音频播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在许多不同的网络浏览器和不同版本中播放音频文件.旧系统产生 4 位 WAV 文件,许多浏览器无法处理.所有文件都包含合成或录制的人声.反正我得换了所以我的问题是:

1) 在兼容性、大小和质量方面,用于音频文件的最佳文件格式是什么?

2) 使用 HTML5 并保持向后兼容的最佳方式是什么?

我们需要支持 Internet Explorer 版本 6、7、8 和 9;Firefox、Chrome 和 Safari.

更新:终于让它适用于 IE 6-9、Firefox 和 Chrome;还没有测试 Safari.我了解到 Windows 版 Safari 需要 Quicktime,而 IE 需要 Windows 媒体播放器.

解决方案

这是我正在使用的:

<音频自动播放><source src="/static/sound/SOUND.mp3" type="audio/mpeg"><source src="/static/sound/SOUND.ogg" type="audio/ogg"><source src="/static/sound/SOUND.wav" type="audio/wav"><source src="/static/sound/SOUND.aiff" type="audio/x-aiff"><对象><param name="autostart" value="true"><param name="src" value="/static/sound/SOUND.mp3"><param name="autoplay" value="true"><param name="controller" value="false"><embed src="/static/sound/SOUND.mp3" controller="false" autoplay="true" autostart="true" type="audio/mpeg"></embed></对象>

我以 MP3、OGG、WAV 和 AIFF 格式提供相同的音频剪辑,然后让浏览器选择要播放的剪辑.audio 标签用于 HTML5,object 标签用于旧系统,embed 适用于一些不支持 object 标签的系统.>

我从几个网站上的一些信息中收集到的,但不幸的是我忘记了网址.

更新

我已经改用 howler.js 来处理这些事情.它会自动处理所有与声音相关的跨浏览器问题.不幸的是,它不支持 IE 6-8,但我已经放弃以任何方式支持它们.

I need to playback audio files in many different web browsers and different versions. The old system produces 4-bit WAV files, which many browsers can't handle. All files contain synthesized or recorded human voices. Anyway I'm gonna need to replace it. So my questions are:

1) what is the best file format to use for audio files, with regards to compatibility, size and quality?

2) what is the best way to use HTML5 and staying backwards-compatible?

We need to support Internet Explorer versions 6, 7, 8 and 9; Firefox, Chrome and Safari.

Update: finally got it working for IE 6-9, Firefox and Chrome; haven't tested Safari yet. I learned that Safari for windows requires Quicktime and IE requires windows media player.

解决方案

Here's what I'm using:

<audio autoplay>
    <source src="/static/sound/SOUND.mp3" type="audio/mpeg">
    <source src="/static/sound/SOUND.ogg" type="audio/ogg">
    <source src="/static/sound/SOUND.wav" type="audio/wav">
    <source src="/static/sound/SOUND.aiff" type="audio/x-aiff">
    <object>
        <param name="autostart" value="true">
        <param name="src" value="/static/sound/SOUND.mp3">
        <param name="autoplay" value="true">
        <param name="controller" value="false">
        <embed src="/static/sound/SOUND.mp3" controller="false" autoplay="true" autostart="true" type="audio/mpeg"></embed>
    </object>
</audio>

I provide the same audio clip in MP3, OGG, WAV, and AIFF and then let the browser pick which it wants to play. The audio tag is for HTML5, the object tag is for older systems, and embed works on some systems not supporting the object tag.

I put this together from some information on a few websites, but unfortunately I've forgotten the URL.

UPDATE

I've since switched to using howler.js for this stuff. It automatically deals with all the cross-browser issues related to sound. Unfortunately it doesn't support IE 6-8, but I've given up supporting those any way.

这篇关于向后和跨浏览器兼容的音频播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆