【问题标题】:audio tag works in chrome but not in Firefoxaudio 标签在 chrome 中有效,但在 Firefox 中无效
【发布时间】:2012-02-13 20:20:05
【问题描述】:

此代码在 Chrome 中运行良好,但在 Firefox 中不产生音频。我正在从 file:// 而不是 http:// 进行测试。我在 playSound 函数中放置了一个警报,并将音频参数传递给它。它返回了所有按钮的音频 div id,就像它应该的那样。在这一点上我很难过,任何建议都会很棒。

 <li id="siren" class="app_button">
   <img src="img/siren.png" alt=""
     name="siren_pressed" width="102" height="102"
     onmousedown="press('siren_pressed')" 
     onmouseup="release('siren_pressed'), playSound('siren_audio')">
   <audio id="siren_audio">
     <source src="audio/siren.ogg" type="audio/ogg">
     <source src="audio/siren.mp3" type="audio/mpeg">
   </audio>
 </li>

  /* Javascript is in a seperate folder */

  function playSound(audio)
  {
    var sound = document.getElementById(audio);
    sound.play();
  }

【问题讨论】:

  • 你检查过这个线程吗...以防万一...:stackoverflow.com/questions/8831625/…
  • 是的,我确实检查了该线程。它没有帮助。
  • 我回顾了你提到的那个话题。我尝试直接播放 .mp3 文件,效果很好。 .ogg 文件显示了一个灰色框,里面有一个“x”。我点击了“x”,它变成了一个音频播放器,但不会播放文件。我现在有一些问题要解决。感谢您再次支持我的努力。

标签: javascript html firefox google-chrome audio


【解决方案1】:

解决了!它是 .ogg 文件。我最初在命令行中使用 ffmpeg 将它们从 mp3 转换为 ogg。在浏览器中单独测试音频显示 chrome 和 firefox 上的 ogg 存在问题。我下载了一个不同的声音转换器并再次尝试。这次 ogg 文件在两个浏览器上都没有问题。感谢@Golmaal 为我指明了正确的方向。

【讨论】:

    猜你喜欢
    • 2014-08-04
    • 2016-02-19
    • 2022-01-23
    • 1970-01-01
    • 2020-04-04
    • 2011-03-16
    • 2015-06-11
    • 2018-07-05
    • 2014-08-18
    相关资源
    最近更新 更多