首页 > Web开发 > 详细

web 音频文件自动播放(兼容所有浏览器)

时间:2015-05-12 15:17:28      阅读:377      评论:0      收藏:0      [点我收藏+]
function AudioPerform() {
            var ua = navigator.userAgent.toLowerCase();
            var audiopath = "$!{TempletPath}images/ring.wav";
            if (ua.match(/msie ([\d.]+)/)) {
                jQuery(‘#alert_sound‘).html(‘<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95"><param name="AutoStart" value="1" /><param name="Src" value="‘ + audiopath + ‘" /></object>‘);
            }
            else if (ua.match(/firefox\/([\d.]+)/)) {
                //            jQuery(‘#alert_sound‘).html(‘<embed src="‘ + audiopath + ‘" type="audio/wav" hidden="true" loop="false" mastersound></embed>‘);
                jQuery(‘#alert_sound‘).html(‘<audio autoplay="autoplay"><source src="‘ + audiopath + ‘" type="audio/wav"/><source src="$!{TempletPath}images/ring.wav" type="audio/mpeg"/></audio>‘);
            }
            else if (ua.match(/chrome\/([\d.]+)/)) {
                jQuery(‘#alert_sound‘).html(‘<audio src="‘ + audiopath + ‘" type="audio/wav" autoplay=”autoplay” hidden="true"></audio>‘);
            }
            else if (ua.match(/opera.([\d.]+)/)) {
                jQuery(‘#alert_sound‘).html(‘<embed src="‘ + audiopath + ‘" hidden="true" loop="false"><noembed><bgsounds src=‘ + audiopath + ‘></noembed>‘);
            }
            else if (ua.match(/version\/([\d.]+).*safari/)) {
                jQuery(‘#alert_sound‘).html(‘<audio src="‘ + audiopath + ‘" type="audio/wav" autoplay=”autoplay” hidden="true"></audio>‘);
            }
            else {
                jQuery(‘#alert_sound‘).html(‘<embed src="‘ + audiopath + ‘" type="audio/wav" hidden="true" loop="false" mastersound></embed>‘);
            }
        }

 

web 音频文件自动播放(兼容所有浏览器)

原文:http://www.cnblogs.com/f-zp/p/4497213.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!