html - 为什么我的 HTML5 音频不循环播放?

标签 html audio

网站位于:http://ajf.me/stuff/eva在撰写本文时。源代码是这样的:

<!DOCTYPE html>
<html style="height: 100%;">
<head>
<title>eva</title>
</head>
<body style="background-color: black; background-image: url('eva.png'); background-repeat: no-repeat; background-position: center center; height: 100%; margin: 0px; padding: 0px;">
<audio autoplay loop>
    <source src="eva.mp3" type="audio/mpeg" />
    <source src="eva.ogg" type="audio/ogg" />
    <source src="eva.wav" type="audio/wav" />
</audio>
</body>
</html>

音频在 Chrome、IE9 和 Firefox 中播放良好,但在后者中不循环播放。音频文件不能变形,因为它是由 Audacity 制作的。为什么它不循环还有其他解释吗?

最佳答案

你可以这样做

<audio autoplay loop>

属性不需要有任何其他内容。


编辑

据此,Firefox 不喜欢 loop .它提出了一个 js 解决方案:

document.getElementById('audio_2').addEventListener('ended', function(){
    this.currentTime = 0;
}, false);

http://forestmist.org/2010/04/html5-audio-loops/


编辑

HTML5 音频循环现在适用于 firefox。在 26.0 版中确认(可能更早)

关于html - 为什么我的 HTML5 音频不循环播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7747526/

相关文章:

javascript - 按下按键时如何以鼠标位置为中心绘制圆

javascript - JQuery Collapsible Div 仅在第一次时正确显示

html - 如何随着列表的增长扩展列表的高度?

html - CSS HTML 当我以像素为单位指定宽度时,为什么会根据屏幕宽度调整大小?

安卓声音合成

Java Wav 文件错误(javax.sound.sampled.UnsupportedAudioFileException : could not get audio input stream from input file)

c# - 使用 AngleSharp 解析 CSS

ios - AirPlay:通过显示可用设备弹出窗口重定向音频

python - 在python中生成正弦波声音

php - 如何使用php将音频消息嵌入音频文件?