HTML5 audio标签使用 浏览器触发函数提示声音(最小化后 、当前任务非浏览器时都可以使用)

本文介绍了一种在浏览器中利用HTML5的audio标签实现定时播放音频的方法,并提供了一个具体的示例代码,展示了如何通过JavaScript设置定时器来控制音频的播放。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、上次写过一个浏览器播放提示音  但使用过程中不是很理想

(1)当前任务不是浏览器时(最前端运行浏览器)事件堆积到一起不执行  执行时一下子触发好多提示音

2、audio标签不存在这个问题具体代码如下

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script>


 setInterval("myInterval()",5000);//1000为1秒钟
       function myInterval()
       {
document.getElementById('myTune').play();
        }

</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>one</title>
</head>


<body>
<h5>sgmlp</h5>
<div id="content"> 
  <div style="margin-bottom: 20px;"> 
    <button id="playButton" onclick="document.getElementById('myTune').play()">Play Music</button> 
    <button id="pauseButton" onclick="document.getElementById('myTune').pause()">Pause Music</button> 
    <button id="stopButton" onclick="document.getElementById('myTune').pause(); document.getElementById('myTune').currentTime = 0;">Stop Music</button> 
  </div> 
  <audio id="myTune"> 
    <source src="6138.mp3"> 
  </audio> 
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值