您的位置:首页 > Web前端 > HTML5

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

2016-03-24 17:40 681 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  js html html5 函数 浏览器