anxiao_web/pages/cmddispatch/audio/audio.js

174 lines
4.2 KiB
JavaScript
Raw Normal View History

2024-07-24 09:22:32 +08:00
var deviceSosAlarmList=[];
var deviceSosAudioTimer=null;
var deviceSosAudio=null;
//设备报警声音
function playDeviceSosAudio(deviceid){
var flag=0;
for(var i=0;i<deviceSosAlarmList.length;i++){
if(deviceSosAlarmList[i]==deviceid){
flag++;
}
}
if(flag==0){
deviceSosAlarmList.push(deviceid);
}
if(deviceSosAudio==null){
deviceSosAudio=new Audio('./pages/cmddispatch/audio/sosAlarm.mp3');
deviceSosAudio.addEventListener("canplay", function(){//监听audio是否加载完毕
deviceSosAudio.play();
})
}
if(deviceSosAudioTimer==null){
deviceSosAudioTimer=setInterval(() => {
if(deviceSosAlarmList.length!=0){
deviceSosAudio.play();
}
},5000);
}
}
//取消设备声音
function stopDeviceSosAudio(deviceid){
//直接不响
for(var i=0;i<deviceSosAlarmList.length;i++){
if(deviceid==deviceSosAlarmList[i]){
deviceSosAlarmList.splice(i,1);
break;
}
}
if(deviceSosAlarmList.length==0){
if(deviceSosAudioTimer!=null){
clearInterval(deviceSosAudioTimer);
deviceSosAudioTimer=null;
}
if(deviceSosAudio!=null){
deviceSosAudio.pause();
deviceSosAudio=null;
}
}
}
var pushButtonTimer=null;
var pushButtonAlarmDeviceList=[];
var pushButtonAudio=null;
//报警按钮请求声音
function playPushButtonAudio(deviceid){
var flag=0;
for(var i=0;i<pushButtonAlarmDeviceList.length;i++){
if(pushButtonAlarmDeviceList[i]==deviceid){
flag++;
}
}
if(flag==0){
pushButtonAlarmDeviceList.push(deviceid);
}
if(pushButtonAudio==null){
pushButtonAudio=new Audio('./audio/sosAlarm.mp3');
pushButtonAudio.addEventListener("canplay", function(){//监听audio是否加载完毕
pushButtonAudio.play();
});
}
if(pushButtonTimer==null){
pushButtonTimer=setInterval(() => {
if(pushButtonAlarmDeviceList.length!=0){
pushButtonAudio.play();
}
},1000);
}
}
//报警按钮关闭声音
function stopPushButtonAudio(deviceid){
//直接不响
for(var i=0;i<pushButtonAlarmDeviceList.length;i++){
if(deviceid==pushButtonAlarmDeviceList[i]){
pushButtonAlarmDeviceList.splice(i,1);
break;
}
}
if(pushButtonAlarmDeviceList.length==0){
if(pushButtonTimer!=null){
clearInterval(pushButtonTimer);
pushButtonTimer=null;
}
if(pushButtonAudio!=null){
pushButtonAudio.pause();
pushButtonAudio=null;
}
}
}
var videoRequireTimer=null;
var videoRequireList=[];
var videoRequireAudio=null;
//可视对讲请求声音
function playVideoRequireAudio(deviceid){
var flag=0;
for(var i=0;i<videoRequireList.length;i++){
if(videoRequireList[i]==deviceid){
flag++;
}
}
if(flag==0){
videoRequireList.push(deviceid);
}
if(videoRequireAudio==null){
videoRequireAudio=new Audio('./audio/videoReq.mp3');
videoRequireAudio.addEventListener("canplay", function(){//监听audio是否加载完毕
videoRequireAudio.play();
})
}
if(videoRequireTimer==null){
videoRequireTimer=setInterval(() => {
if(videoRequireList.length!=0){
videoRequireAudio.play();
}
},5000);
}
}
//可视对讲关闭声音
function stopVideoRequireAudio(deviceid){
//直接不响
for(var i=0;i<videoRequireList.length;i++){
if(deviceid==videoRequireList[i]){
videoRequireList.splice(i,1);
break;
}
}
if(videoRequireList.length==0){
if(videoRequireTimer!=null){
clearInterval(videoRequireTimer);
videoRequireTimer=null;
}
if(videoRequireAudio!=null){
videoRequireAudio.pause();
videoRequireAudio=null;
}
}
}
export {
playDeviceSosAudio,
stopDeviceSosAudio,
playPushButtonAudio,
stopPushButtonAudio,
playVideoRequireAudio,
stopVideoRequireAudio
}