[英]HTML 5 play audio file on click mobile devices
我想点击一个音频文件。 我正在使用的代码在浏览器中工作正常但似乎不适用于任何移动设备。 有什么我想念的吗?
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<audio id="audio" src="http://ricklemon.co.uk/game/sound.ogg" autostart="false" ></audio>
<a onclick="PlaySound()"><img src="http://ricklemon.co.uk/game/images/speaker.png" width="200px" /></a>
<script>
function PlaySound() {
var sound = document.getElementById("audio");
sound.play()
}
</script>
</body>
</html>
您的问题是ogg音频文件既不适用于Windows手机也不适用于ios,因此您应该添加另一个扩展名为.mp3的文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.