[英]audio autoplay not working html5
Something really akward is happening in my code, the autoplay for audio is not working. 我的代码中确实发生了一些奇怪的事情,音频的自动播放不起作用。
Basically, every website code that i put this code the music autoplays but in this one is not working. 基本上,我在音乐中自动播放此代码的每个网站代码都无法播放。
Find the footer code: 查找页脚代码:
<footer>
<ul>
<h1>
<a href="#"><img src="images/topoPirelli.png" alt=""></a>
</h1>
</ul>
<audio class="audio" loop autoplay="autoplay" controls>
<source src="1.ogg" type="audio/ogg">
<source src="1.mp3" type="audio/mpeg">
</audio>
</footer>
</div>
</body>
</html>
I had the same problem. 我有同样的问题。 I solved it by using jquery in the end:
我最后使用jquery解决了它:
$('audio').on('canplay', function() {
this.play();
});
Edit: Nowadays I noticed a lot of browsers don't allow autoplay to work if the video sound. 编辑:如今,我注意到许多浏览器都不允许自动播放视频声音。 So a solution could be adding the
muted
attribute. 因此,解决方案可能是添加
muted
属性。
<video autoplay muted>
Try this: 尝试这个:
<audio class="audio" controls autoplay>
<source src="./1.ogg" type="audio/ogg">
<source src="./1.mp3" type="audio/mpeg">
<!-- <embed height="50" width="100" src="./1.mp3"> NOT NECESSARY -->
</audio>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.