• 0
  • 0

// 跨平台播放音效

2019-06-24 183 0 admin 所属分类:Javascript
function AudioPerform(identifier, closetime) {
    var ua = navigator.userAgent.toLowerCase();
    var audiopath = "./source/plugin/" + identifier + "/image/tip.mp3";
    var ele = layui.$('#alert_sound');
    if (ele.length == 0) {
        layui.$('body').append('<div id="alert_sound"></div>')
    }
    if (ua.match(/msie ([\d.]+)/)) {
        layui.$('#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.]+)/)) {
        layui.$('#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.]+)/)) {
        layui.$('#alert_sound').html('<audio src="' + audiopath + '" type="audio/wav" autoplay=”autoplay” hidden="true"></audio>');
    } else if (ua.match(/opera.([\d.]+)/)) {
        layui.$('#alert_sound').html('<embed src="' + audiopath + '" hidden="true" loop="false"><noembed><bgsounds src=' + audiopath + '></noembed>');
    } else if (ua.match(/version\/([\d.]+).*safari/)) {
        layui.$('#alert_sound').html('<audio src="' + audiopath + '" type="audio/wav" autoplay=”autoplay” hidden="true"></audio>');
    } else {
        layui.$('#alert_sound').html('<embed src="' + audiopath + '" type="audio/wav" hidden="true" loop="false" mastersound></embed>');
    }
    if (closetime != undefined) {
        setTimeout(function() {
            layui.$('#alert_sound').remove();
        }, closetime);
    }
}


返回顶部