You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

79 lines
2.5 KiB

var lastRunTime;
var src = "../_files/_p/2125.mp3";
var src1 = "../_files/_p/huozaijingbaosheng.mp3";
function paly() {
var currentTime = Date.now();
var protectTime = 5000; //设置保护性延时 单位毫秒,不要小于50 建议100以上
if (lastRunTime && (currentTime - lastRunTime) < protectTime) {
//console.log(currentTime - lastRunTime);
return; //两次执行太过频繁,直接退出
} else {
playSound();
lastRunTime = Date.now();
}
}
function paly1() {
var currentTime = Date.now();
var protectTime = 5000; //设置保护性延时 单位毫秒,不要小于50 建议100以上
if (lastRunTime && (currentTime - lastRunTime) < protectTime) {
//console.log(currentTime - lastRunTime);
return; //两次执行太过频繁,直接退出
} else {
playSound1();
lastRunTime = Date.now();
}
}
var playSound1 = function () {
var strAudio = "<iframe allow='autoplay' id='audioPlay' src='" + src1 + "' hidden='true' style='display:none;' />";
if ($("#audioPlay").length <= 0) {
$("body").append(strAudio);
}
console.log($("#audioPlay"));
$("#audioPlay").attr("src", src1);
}
var playSounda = function () {
var strAudio = '<audio src="' + src + '" controls="controls" preload id="audioPlay" hidden>';
if ($("#audioPlay").length <= 0) {
$("body").append(strAudio);
}
$("#audioPlay")[0].play();
}
var playSound = function () {
// var borswer = window.navigator.userAgent.toLowerCase();
// if (borswer.indexOf("ie") >= 0) {
// //IE内核浏览器
// var strEmbed = '<embed name="embedPlay" src="/admin/images/30.wav" autostart="true" hidden="true" loop="false"></embed>';
// if ( $( "body" ).find( "embed" ).length <= 0 )
// $( "body" ).append( strEmbed );
// var embed = document.embedPlay;
// //浏览器不支持 audion,则使用 embed 播放
// embed.volume = 100;
// //embed.play();这个不需要
// } else {
//非IE内核浏览器
var strAudio = "<iframe allow='autoplay' id='audioPlay' src='" + src + "' hidden='true' style='display:none;' />";
if ($("#audioPlay").length <= 0) {
$("body").append(strAudio);
}
console.log($("#audioPlay"));
$("#audioPlay").attr("src", src);
// }
}