【问题标题】:Cross-browser audio problems跨浏览器音频问题
【发布时间】:2013-01-19 02:18:42
【问题描述】:

我希望创建一个自动播放一些声音的音频播放器,然后我可以通过控制面板对其进行控制。我试图让它跨浏览器工作,但有一个巨大的头痛。任何帮助将不胜感激。会有多种声音,所有声音都可以通过一组加号和减号来控制音量,所有声音都在加载时开始并循环播放。同样,非常感谢您对实现跨浏览器/设备兼容性的任何帮助。

 <audio id="player" src="assets/forest_ambience_loop.mp3", "assets/forest_ambience_loop.ogg" autoplay loop;>

    </audio>
    <div>
     <button
     onclick="document.getElementById('player').play()">
     Play
     </button>
     <button
     onclick="document.getElementById('player').pause()">
     Pause
     </button>
     <button
     onclick="document.getElementById('player').volume += 0.1">
     Volume Up
     </button>
     <button
     onclick="document.getElementById('player').volume -= 0.1">
     Volume Down
     </button>
    </div>

【问题讨论】:

  • 您需要更具体地了解您遇到的问题。你在哪些浏览器中测试过?哪些行为不符合您的预期?他们的行为与期望的行为有何不同?他们的 JS 控制台中显示了哪些错误?
  • 我在 firefox 和 chrome 中测试过,chrome 工作正常,但 firefox 什么也没做。我知道这是因为 firefox 需要 .ogg 音频,但我不确定如何将其合并到我的音频播放器中

标签: html google-chrome firefox audio opera


【解决方案1】:

&lt;audio&gt; 标签不正确。试试这个,

<audio id="player" controls autoplay loop>
  <source src="assets/forest_ambience_loop.mp3" type="audio/mpeg">
  <source src="assets/forest_ambience_loop.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>

这是工作演示http://jsfiddle.net/bgCTJ/2/

【讨论】:

  • 谢谢你的好先生,还有什么我需要知道的才能在除 firefox/chrome 之外的其他浏览器上工作吗?还是移动设备?编辑:试过这个,它在Firefox中不起作用:(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-18
  • 1970-01-01
  • 2011-03-25
  • 2013-06-01
  • 1970-01-01
相关资源
最近更新 更多