解决视频OCX在调用云台指令使用鼠标事件来发起和结束指令动作无效

社会主义新天地 提交于 2020-03-03 17:00:08

如题:OCX在调用云台指令使用mousedown和mouseup来发送指令和结束指令动作不起作用问题(视频播放和检索在requireJS封装都是正常的)。

在项目中使用requireJS封装了视频控件,但是在指令调用这块始终有问题,经过分析和测试发现:

  • mousedown和mouseup间隔时间一般只有100多ms
  • ocx方法直接调用可以请求,说明ocx不能离开上下文
  • mousedown和mouseup事件之间肯定有某种因素干扰了执行(时间、空间皆有可能)

requireJS封装

下面的方法采用requrejs封装调用:

/* $("#yt_direction_top").on('mousedown',function(){
     upstart();
}); */
function upstart(){
    require(['videoStart'],function(video){
        video.upstart();
    });
}
/* $("#yt_direction_top").on('mouseup',function(){
     upstop();
}); */
function upstop(){
    require(['videoStart'],function(video){
        video.upstop();
    });
}
/* $("#yt_direction_bottom").on('mousedown',function(){
     downstart();
}); */
function downstart(){
    require(['videoStart'],function(video){
        video.downstart();
    });
}
/* $("#yt_direction_bottom").on('mouseup',function(){
     downstop();
}); */
function downstop(){
    require(['videoStart'],function(video){
        video.downstop();
    });
}
/* $("#yt_direction_left").on('mousedown',function(){
     leftstart();
}); */
function leftstart(){
    require(['videoStart'],function(video){
        video.leftstart();
    });
}
/* $("#yt_direction_left").on('mouseup',function(){
     leftstop();
});  */
function leftstop(){
    require(['videoStart'],function(video){
        video.leftstop();
    });
}
/* $("#yt_direction_right").on('mousedown',function(){
     rightstart();
}); */
function rightstart(){
    require(['videoStart'],function(video){
        video.rightstart();
    });
}
/* $("#yt_direction_right").on('mouseup',function(){
     rightstop();
}); */
function rightstop(){
    require(['videoStart'],function(video){
        video.rightstop();
    });
}
/* $("#yt_zoom_add").on('mousedown',function(){
     ZOOMstart();
}); */
function ZOOMstart(){
    require(['videoStart'],function(video){
        video.ZOOMstart();
    });
}
/* $("#yt_zoom_add").on('mouseup',function(){
     ZOOMstop();
}); */
function ZOOMstop(){
    require(['videoStart'],function(video){
        video.ZOOMstop();
    });
}
/* $("#yt_zoom_reduce").on('mousedown',function(){
     REDUCEZOOMstart();
}); */
function REDUCEZOOMstart(){
    require(['videoStart'],function(video){
        video.REDUCEZOOMstart();
    });
}
/* $("#yt_zoom_reduce").on('mouseup',function(){
     REDUCEZOOMstop();
});  */
function REDUCEZOOMstop(){
    require(['videoStart'],function(video){
        video.REDUCEZOOMstop();
    });
}
/* $("#yt_focus_add").on('mousedown',function(){
     FOCUSstart();
}); */
function FOCUSstart(){
    require(['videoStart'],function(video){
        video.FOCUSstart();
    });
}
/* $("#yt_focus_add").on('mouseup',function(){
     FOCUSstop();
});  */
function FOCUSstop(){
    require(['videoStart'],function(video){
        video.FOCUSstop();
    });
}
/* $("#yt_focus_reduce").on('mousedown',function(){
     REDUCEFOCUSstart();
}); */
function REDUCEFOCUSstart(){
    require(['videoStart'],function(video){
        video.REDUCEFOCUSstart();
    });
}
/* $("#yt_focus_reduce").on('mouseup',function(){
     REDUCEFOCUSstop();
}); */
function REDUCEFOCUSstop(){
    require(['videoStart'],function(video){
        video.REDUCEFOCUSstop();
    });
}
/* $("#yt_aperture_add").on('mousedown',function(){
     APERTUREstart();
}); */
function APERTUREstart(){
    require(['videoStart'],function(video){
        video.APERTUREstart();
    });
}
/* $("#yt_aperture_add").on('mouseup',function(){
     APERTUREstop();
});  */
function APERTUREstop(){
    require(['videoStart'],function(video){
        video.APERTUREstop();
    });
}
/* $("#yt_aperture_reduce").on('mousedown',function(){
     REDUCEAPERTUREstart();
}); */
function REDUCEAPERTUREstart(){
    require(['videoStart'],function(video){
        video.REDUCEAPERTUREstart();
    });
}
/* $("#yt_aperture_reduce").on('mouseup',function(){
     REDUCEAPERTUREstop();
}); */
function REDUCEAPERTUREstop(){
    require(['videoStart'],function(video){
        video.REDUCEAPERTUREstop();
    });
}

OCX html页面的纯调用方式

下面的跟<object > 控件在同一页面声明调用:

    function getChannelId(){
        return mini.get("CHANNEL_LIST").getValue();
    }
    function upstart() {
        //第二个参数 1 上 1下  2 左 3 右 4        
        var Res = ocx.PTZControl(getChannelId(), 1, 6, 0);
 
    }
    function upstop() {
        var Res = ocx.PTZControl(getChannelId(), 1, 6, 1);
 
    }
    function downstart() {
        var Res = ocx.PTZControl(getChannelId(), 1, 6, 0);
    }
    function downstop() {
        var Res = ocx.PTZControl(getChannelId(), 1, 6, 1);
    }
 
    function leftstart() {
        var Res = ocx.PTZControl(getChannelId(), 2, 6, 0);
    }
    function leftstop() {
        var Res = ocx.PTZControl(getChannelId(), 2, 6, 1);
    }
 
    function rightstart() {
        var Res = ocx.PTZControl(getChannelId(), 3, 6, 0);
    }
    function rightstop() {
        var Res = ocx.PTZControl(getChannelId(), 3, 6, 1);
    }
 
    function ZOOMstart() {
        var Res = ocx.PTZControl(getChannelId(), 8, 6, 0);
    }
    function ZOOMstop() {
        var Res = ocx.PTZControl(getChannelId(), 8, 6, 1);
    }
    function REDUCEZOOMEstart() {
        var Res = ocx.PTZControl(getChannelId(), 11, 6, 0);
    }
    function REDUCEZOOMstop() {
        var Res = ocx.PTZControl(getChannelId(), 11, 6, 1);
    }
 
    function FOCUSstart() {
        var Res = ocx.PTZControl(getChannelId(), 9, 6, 0);
    }
    function FOCUSstop() {
        var Res = ocx.PTZControl(getChannelId(), 9, 6, 1);
    }
    function REDUCEFOCUSEstart() {
        var Res = ocx.PTZControl(getChannelId(), 12, 6, 0);
    }
    function REDUCEFOCUSstop() {
        var Res = ocx.PTZControl(getChannelId(), 12, 6, 1);
    }
 
    function APERTUREstart() {
        var Res = ocx.PTZControl(getChannelId(), 10, 6, 0);
    }
    function APERTUREstop() {
        var Res = ocx.PTZControl(getChannelId(), 10, 6, 1);
    }
    function REDUCEAPERTUREstart() {
        var Res = ocx.PTZControl(getChannelId(), 13, 6, 0);
    }
    function REDUCEAPERTUREstop() {
        var Res = ocx.PTZControl(getChannelId(), 13, 6, 1);
    }
 
    function startTalk() {
        var Res = ocx.TalkControl(getChannelId(), 0);
    }
 
    function stopTalk() {
        var Res = ocx.TalkControl(getChannelId(), 1);
    }

解决方法:抽离这部分mousedown和mouseup方法在页面中直接调用,不需要再封装处理。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!