如何使用javascript和html循环mp3文件
感谢您的关注,今天我决定在我的网站上添加一些声音,这就是问题所在,关键是按下按钮,mp3就会循环,我知道它可以使用wav,但不能使用mp3,所以我的问题是。我可以调整脚本以使mp3循环吗 javascript:如何使用javascript和html循环mp3文件,javascript,html,loops,button,mp3,Javascript,Html,Loops,Button,Mp3,感谢您的关注,今天我决定在我的网站上添加一些声音,这就是问题所在,关键是按下按钮,mp3就会循环,我知道它可以使用wav,但不能使用mp3,所以我的问题是。我可以调整脚本以使mp3循环吗 javascript: <script language="javascript" type="text/javascript"> function playSound(soundfile) { var type_attr = ''; if (navigator.
<script language="javascript" type="text/javascript">
function playSound(soundfile) {
var type_attr = '';
if (navigator.userAgent.indexOf('Firefox') != -1) {
type_attr = "type=\"application/x-mplayer2\"";
}
document.getElementById("dummy").innerHTML = "<embed src=\"" + soundfile + "\" hidden=\"true\" autostart=\"true\" loop=\"true\" " + type_attr + " />";
}
</script>
功能播放声音(声音文件){
var type_attr='';
if(navigator.userAgent.indexOf('Firefox')!=-1){
type_attr=“type=\”应用程序/x-mplayer2\”;
}
document.getElementById(“dummy”).innerHTML=“”;
}
Html:
我不想使用wav的原因是因为声音文件的容量为+/-1mb(我打算使用很多),而且我负担不起一个大的托管计划,所以我宁愿使用mp3。我希望有可能
谢谢,迪德里克。在网页上,他们描述了如何播放mp3声音的不同解决方案。我试过了
HTML5音频元素,它甚至适用于有mp3的循环(有时加载mp3需要一段时间,但几秒钟后声音在循环中开始)
函数播放\暂停(){
var myAudio=document.getElementById(“myAudio”);
如果(myAudio.paused){
myAudio.play();
}否则{
myAudio.pause();
}
}
播放/暫停
您的浏览器不支持此音频格式。
<span id="dummy">
<tr>
<td><input type="button" class='gstring' value="G" width="50" height="50" onClick="playSound('violin/Gstring.mp3')"></td>
<td><input type="button" class='gstring' value="D" width="50" height="50" onClick="playSound('violin/Dstring.mp3')"></td>
<td><input type="button" class='gstring' value="A" width="50" height="50" onClick="playSound('violin/Astring.mp3')"></td>
<td><input type="button" class='gstring' value="E" width="50" height="50" onClick="playSound('violin/Estring.mp3')"></td>
<td><input type="button" class='g2string' value="STOP" width="70" height="50" onClick="playSound('')"></td>
</tr>
</span>
<!DOCTYPE html>
<html>
<script>
function play_pause() {
var myAudio = document.getElementById("myAudio");
if (myAudio.paused) {
myAudio.play();
} else {
myAudio.pause();
}
}
</script>
<body>
<button type="button" onclick="play_pause()">Play/Pause</button>
<audio id="myAudio" preload loop>
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support this audio format.
</audio>
</body>