zoukankan      html  css  js  c++  java
  • JS播放声音

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>JS播放声音</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
    </head>
    <body>
    <script language="javascript">
    playVoice();
    function playVoice()
        {
          var borswer = window.navigator.userAgent.toLowerCase();
          if(borswer.indexOf( "ie" ) >= 0)
          {
            //IE内核浏览器
            var strEmbed = '<embed name="embedPlay" src="dingdong.wav" autostart="true" hidden="true" loop="false"></embed>';
            if ($("body").find("embed").length <= 0){
                $("body").append(strEmbed);
            }
           var embed = document.embedPlay;
     
            //浏览器不支持 audio,则使用 embed 播放
            embed.volume = 100;
          }else{
            //非IE内核浏览器
            var strAudio = "<audio id='audioPlay' src='dingdong.wav' hidden='true'>";
            if($("body").find("audio").length <= 0){
             $("body").append(strAudio);
            }
            var audio = document.getElementById("audioPlay");
     
            //浏览器支持 audio
            audio.play();
          }
        }
    </script>
    </body>
    </html>
    

      dingdong.wav为声音文件,放在HTML文件相同目录下

    转自:https://blog.csdn.net/quincylk/article/details/77853880

  • 相关阅读:
    Gson字符串编码,字符串转换成图片保存,二进制转换成图片保存
    时间工具类DateUtil
    RSA 签名、验证、加密、解密帮助类
    富友数据加密解密
    Base64(2)
    MD5(2)
    实体对象操作工具
    HttpClient工具类
    MD5
    身份证算法实现
  • 原文地址:https://www.cnblogs.com/yangyangblog/p/10552666.html
Copyright © 2011-2022 走看看