延迟后播放音频标签吗? [英] Have audio tag play after a delay?

查看:85
本文介绍了延迟后播放音频标签吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用HTML5中的< audio> 标签播放MP3。

 < audio controls =controlsautoplay =autoplay> 
< source src =song.mp3type =audio / mp3/>
< / audio>

这很好,但我想知道如何在歌曲开始自动播放之前将延迟?我知道没有延迟属性,但是我认为它可以通过javascript来完成?

解决

 <>< code>< ; audio controls =controlsonloadeddata =var audioPlayer = this; setTimeout(function(){audioPlayer.play();},> 
< source src =Kalimba.mp3type =audio / mp3/>
< / audio>


I'm playing an MP3 using the <audio> tag in HTML5.

<audio controls="controls" autoplay="autoplay">
  <source src="song.mp3" type="audio/mp3" />
</audio>

This works fine, but I am wondering how I can put a delay in before the song starts to autoplay? I know there's not a delay attribute, but I'm thinking it could be accomplished via javascript?

解决方案

Try this, really simple but you should move the JS outside the markup...

<audio controls="controls" onloadeddata="var audioPlayer = this; setTimeout(function() { audioPlayer.play(); }, 8000)">
    <source src="Kalimba.mp3" type="audio/mp3" />
</audio>

这篇关于延迟后播放音频标签吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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