为什么我的 HTML5 音频不会循环播放? [英] Why won't my HTML5 audio loop?

查看:16
本文介绍了为什么我的 HTML5 音频不会循环播放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该网站当时位于:http://ajf.me/stuff/eva的写作.源代码是这样的:

The site is up at: http://ajf.me/stuff/eva at the time of writing. The source code is this:

<!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 制作的.有没有其他解释为什么它不循环?

The audio plays fine in Chrome, IE9, and Firefox, but does not loop in the latter. The audio file can't be malformed, as it was produced by Audacity. Is there any other explanation for why it doesn't loop?

推荐答案

你可以这样做

<音频自动播放循环>

属性不需要其他任何东西.

The attributes do not need to have anything else.

编辑

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

According to this, Firefox doesn't like loop. It suggests a js solution:

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

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

编辑

HTML5 音频循环现在可与 firefox 配合使用.26.0版本确认(可能更早)

HTML5 audio loop now works with firefox. Confirmed in version 26.0 (might have been earlier)

这篇关于为什么我的 HTML5 音频不会循环播放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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