var audio = document.getElementById("myAudio");var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;if(!(isIE||isEdge||isIE11)){//非ie浏览器 audio.addEventListener('playing', function () { $(':button').attr("disabled",true); }, false); audio.addEventListener('ended', function () { $(':button').attr("disabled",false); }, false);}
function broadCast(token, zhText) { //判断浏览器 var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器 var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器 var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1; if(isIE||isEdge||isIE11) { //ie浏览器 var voice=document.createElement("bgsound"); document.body.appendChild(voice); var audioSrc = "http://tsn.baidu.com/text2audio?lan=zh&cuid=123&ctp=1&spd=3&tex=" + zhText + "\"&tok=" + token; voice.src=audioSrc; } else{ //不是ie浏览器 if (audio.paused) { //已经播放完毕 var audioSrc = "http://tsn.baidu.com/text2audio?lan=zh&cuid=123&ctp=1&spd=3&tex=" + zhText + "\"&tok=" + token; console.log("--audio:"+audio); console.log("--audioSrc:"+audioSrc); console.log("--audioSrc type:"+ typeof audioSrc); // audio.type='audio/mpeg';// source.src="http://tsn.baidu.com/text2audio?lan=zh&cuid=123&ctp=1&spd=3&tex=hello&tok=24.70b121c60ff4553de615166eb3d8e737.2592000.1553950115.282335-9969555"; audio.src = audioSrc; audio.play(); } else { sleepBroadCast(token, zhText, 1000); } }