为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

How to get Audio html5 tag to work in Firefox

  • 3 个回答
  • 1 人有此问题
  • 22 次查看
  • 最后回复者为 cor-el

more options

Hi guys, I'm having a really annoying problem, in which HTML5 audio tags either do not work at all in Firefox; they have a huge delay before playing, or they play (but with many errors and inconsistencies).

I'm using Firefox 35.0

I'm using ONLY .ogg files

Here is an example of my code:

<audio autoplay="autoplay" controls="controls" id="audio" style="display:none;">
 <source src="Music.ogg"
         type='audio/ogg'>
</audio>

<script>
  myAudio=document.getElementById('audio');
  myAudio.addEventListener('canplaythrough', function() {
    this.currentTime = 1;
    this.play();
  });
</script>

The code is working on both Internet Explorer and Chrome.

When I remove the display:none attribute, the audio player is visible.

Hi guys, I'm having a really annoying problem, in which HTML5 audio tags either do not work at all in Firefox; they have a huge delay before playing, or they play (but with many errors and inconsistencies). I'm using Firefox 35.0 I'm using ONLY .ogg files Here is an example of my code: <pre><nowiki><audio autoplay="autoplay" controls="controls" id="audio" style="display:none;"> <source src="Music.ogg" type='audio/ogg'> </audio> <script> myAudio=document.getElementById('audio'); myAudio.addEventListener('canplaythrough', function() { this.currentTime = 1; this.play(); }); </script></nowiki></pre> The code is working on both Internet Explorer and Chrome. When I remove the display:none attribute, the audio player is visible.

由cor-el于修改

所有回复 (3)

more options

I've called the big guys to help you. Good luck.

more options

Hi there, I appreciate the response. Fortunately, I just figured out what the cause of the problem was!

For some reason, the Javascript I was using broke the sound in Firefox. Without the script part, the sound works fine.

This creates a couple of new functionality problems, but they don't have anything to do with Firefox.

Thanks for helping me, hopefully I'll be able to find some way to keep the functionality but have it work in FF.

more options

You can also try to set the width:0px and height:0px and instead of using display:none