• 前端实现: 抓拍和定时弹出任务


    1.代码示例

    <html>
      <head>
        <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://cdn.bootcss.com/jquery-json/2.6.0/jquery.json.min.js"></script>
      </head>
      <body>
        <!-- <a href="javascript:;" onClick="playorpause()">播放视频</a> -->
        <div class="video" style=" 100%;height: 100%;"></div>
        <div id="problems" style="display: none;"> </div>
    
        <div id="problems2" style="display: none">
      <div class="content">
        <div class="hide_box"></div>
        <div id="heihei" class="shang_box" style="display: none;">
          <div class="shang_tit">
            <p>采集信息</p>
          </div>
          <div class="problem_order">
            <div class="problem_answer">
    
              <br/>
              <video id="v" style=" 192px;height: 144px;"></video>
              <img src="" id="photo" alt="photo" style=" 192px;height: 144px; float: right;">
              <canvas id="canvas" style="display:none;"></canvas>
              <br/>
    
            </div>
          </div>
    
          <div class="order_info" style="display: none;"><p id="order_info_p"></p></div>
          <div class="shang_payselect">
            <button class="btn-common" id="take">拍照</button>
          </div>
        </div>
      </div>
    
    </div>
    <script>
        var all_player = ''
        var default_avatar = 'data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QBoRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAMAAAExAAIAAAARAAAATgAAAAAAAJOjAAAD6AAAk6MAAAPocGFpbnQubmV0IDQuMi4xMAAA/9sAQwABAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB/9sAQwEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB/8AAEQgAyADIAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCC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xpF0l5p97EJbe4jPDLyGVlPzJLE4aOaJwrxSo8Uiq6MoK+GvgD47uvD3ii38NXU7nRPEUwgSBmJjtdXkwtvcQqTtT7U220mUAeaZIHLBrdQ5WUouNvM2i7q54Zf3T31/e3rks93d3FyzH7zNPK8xLHucyHr0ORVSiitjAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigC3YXclhfWd9CSstld293EwJBWS3mSZCCMkEMgOQMiiiigD//2Q=='
        var face_url = 'https://mooc.ndmooc.com/tmp/files/image/photo/3/3.jpg'
        var problem_view_ats_list2 = '[0]'
        // console.log('---------',problem_view_ats_list2)
        problem_view_ats_list2 = JSON.parse(problem_view_ats_list2)
        // var problem_view_ats_list2 = [5, '5',600, '600','1200','2400','4800']
        console.log('---------',face_url)
        $('#photo').attr('src', face_url)
    
        function bbb(t) {
            var player_time = player.V.currentTime.toFixed(0);
            settimeFn2(player_time)
        }
    
        function settimeFn2(player_time) {
            //console.log('----------settimeFn2----------')
            var showTime = 2;
            var time = showTime;
            $(document).on('click', function() {
                time = showTime;
            });
            var interCount = setInterval(function() {
                time--;
                if(time == 0) {
                    clearInterval(interCount);
                    var index2 = $.inArray(parseInt(player_time), problem_view_ats_list2);
                    var index3 = $.inArray(player_time.toString(), problem_view_ats_list2);
                    console.log(player_time,problem_view_ats_list2)
                    if(index2 >= 0 || index3 > 0){
                        console.log('---index2!!!!---,')
                        ShowMessage2();
                    }
                }
            }, 1000);
    
            function ShowMessage2() {
                console.log('---ShowMessage2---')
                console.log($('#heihei').css('display'))
                $('#heihei').attr("style",'display: block;')
                $('#problems2').attr("style",'display: block;')
                console.log($('#heihei').attr("style"))
                $('#heihei').css('display','block');
                $('#problems2').css('display','block');
                player.videoPause();
    
    
            };
        }
    </script>
    
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <script>
        // 拍照---------
        !(function () {
            var avatar_video = null
            
            console.log("1111111111111111111")
            if (navigator.mediaDevices === undefined) {
                navigator.mediaDevices = {};
            }
            if (navigator.mediaDevices.getUserMedia === undefined) {
                navigator.mediaDevices.getUserMedia = function (constraints) {
                    var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
                    if (!getUserMedia) {
                        return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
                    }
                    return new Promise(function (resolve, reject) {
                        getUserMedia.call(navigator, constraints, resolve, reject);
                    });
                }
            }
    
            navigator.mediaDevices.getUserMedia({audio: true, video: true})
                .then(function (stream) {
                    var video = document.querySelector('#v');
                    if ("srcObject" in video) {
                        video.srcObject = stream;
                    } else {
                        video.src = window.URL.createObjectURL(stream);
                    }
                    video.onloadedmetadata = function (e) {
                        avatar_video = true
                        video.play();
                    };
                })
                .catch(function (err) {
                    console.log("ERROR");
                    $('#order_info_p').html('加载摄像头失败');
                    $('.order_info').css('display', 'block');
                    console.log(err.name + ": " + err.message);
                });
            
            if (avatar_video) {
                document.getElementById('take').addEventListener('click', function () {
                    paizhao(video)
                }, false);
    
            } else {
                console.log("不支持");
            }
        })();
    
    </script>
    <script>
        var face_url = 'https://mooc.ndmooc.com/tmp/files/image/photo/3/3.jpg'
        console.log('-------face_url-----', face_url)
        function paizhao(video){
            let canvas = document.getElementById('canvas');
            canvas.width = video.videoWidth;
            canvas.height = video.videoHeight;
            canvas.getContext('2d').drawImage(video, 0, 0);
            let data = canvas.toDataURL("image/jpeg", 0.8);
            console.log("---data---", data)
            document.getElementById('photo').setAttribute('src', data);
            var avatar_url = 'https://yykrlc.oss-cn-beijing.aliyuncs.com/2.jpg'
            var face_url = 'https://mooc.ndmooc.com/tmp/files/image/photo/3/3.jpg'
            var avatar_url = face_url
            imagesAjaxFace(data,avatar_url)
        }
    </script>
    <script>
        function imagesAjaxFace(img_base64,avatar_url) {
            var data = {};
            data.img_base64 = img_base64;
            //data.avatar_img_base64 = img_base64;
            data.avatar_url = avatar_url;
            var face_url = 'https://mooc.ndmooc.com/tmp/files/image/photo/3/3.jpg'
            console.log('---imagesAjaxFace---')
    
            $.ajax({
                //url: "http://192.168.1.82:5000/api/v1/dlib/face",
                //url: "https://11.22.com/api/v1/bdaip/face",
                //url: "http://127.0.0.1:5000/api/v1/bdaip/face",
                //url: '/api/v1/common/baidu/face',
                url: '/api/v1/common/baidu/face',
                data: data,
                type: "POST",
                dataType: 'json',
                success: function (re) {
                    console.log(re)
    
                    if(re.aip_face>= 80){
                        $('#heihei').attr("style",'display:none');
                        $('#problems2').attr("style",'display:none');
                        player.videoPlay()
                    }else{
                        $('#order_info_p').html('匹配失败');
                        $('.order_info').attr("style",'display:block');
                        //setTimeout(function(){ $("#take").click() }, 9000);
                    }
                }
            });
        };
    </script>
    
    
        <input type="hidden" value="[]" id="pro">
        <script type="text/javascript">
    
            var idLoadHandler=false;
            var is_live = 'false';
            var course_id = '12';
            var module_id = '16';
            var item_id = '14';
            var problem_view_ats_str = '';
            var problem_view_ats_list = problem_view_ats_str.split(",");
            // var problem_view_ats_list2 = ['5','600','1200','2400','4800']
            // var problem_view_ats_list2 = []
            var problem_json = JSON.parse($("#pro").val());
            // var problem_json = [{ A: "指令寄存器",B: "地址寄存器",C: "指令译码器",D: "地址译码器",id: 16,position: 0,problem_type: "Single",title: "CPU组成中不包括文库         。",
            //                       view_at: "4"},
            //                     { A: "运算器", B: "控制器", C: "存储器",D: "I/O接口",id: 17, position: 0, problem_type: "Single",title: "CPU组成中不包括文库         。",view_at: "16"}]
    
            if(is_live == 'true'){
                is_live = true
            }else{
                is_live = false
            }
            var videoObject = {
                container: '.video',//“#”代表容器的ID,“.”或“”代表容器的class
                variable: 'player',//该属性必需设置,值等于下面的new chplayer()的对象
                loaded: 'loadedHandler',//监听播放器加载成功
                autoplay: true,
                live: is_live,
                video: 'https://moocfiles.ndmooc.com/course/12/videos/2020/06/16/159229134264.mp4'//视频地址
            };
            var player=new ckplayer(videoObject);
    
            var totaltime = player.V.duration;
    
            function loadedHandler(){//播放器加载后会调用该函数
                idLoadHandler=true;
                player.addListener('time', aaa); //监听播放时间,addListener是监听函数,需要传递二个参数,'time'是监听属性,这里是监听时间,timeHandler是监听接受的函数
                player.addListener('time', bbb); //监听播放时间,addListener是监听函数,需要传递二个参数,'time'是监听属性,这里是监听时间,timeHandler是监听接受的函数
            };
    
            var num_1 = 0;
            var times_status = true;
            function aaa(t) {
                //console.log('----------aaaa---------------');
                var player_time = player.V.currentTime.toFixed(0);
                // console.log(player.V.currentTime.toFixed(0));
                num_1 += 1;
                if (num_1 % 30 == 0) {
                    timeHandler(t)
                }
                /*判断是视频下是否存在问题*/
                if (problem_json.length > 0) {
                    settimeFn(player_time)
                }
                // if (1) {
                //     console.log('-----settimeFn2----')
                //     settimeFn2(player_time)
                // }
            }
    
            function timeHandler(t){
                if(!totaltime){totaltime = player.V.duration;}
                // console.log('当前播放的时间:'+ t);
                if(course_id){
                    sync_learn(course_id, module_id, item_id, t)
                }
            }
    
            function sync_learn(course_id, module_id, item_id, time_now){
                $.ajax({
                  url: '/api/v1/personals/courses/'+ course_id +'/modules/'+ module_id +'/items/' + item_id + '/record',
                    type:'get',
                    dataType:'text',
                    data:{
                      starting_time: time_now,
                    },
                    success:function(data){
                        // console.log(data);
                        times_status = false;
                    }
                })
            }
            function loadHandler(){
                idLoadHandler=true;
            }
            function playorpause(){
                if(idLoadHandler){
                    player.playOrPause();
                }
                else{
                    alert('播放器还未加载,不能进行控制');
                }
            }
    
            function settimeFn(player_time) {
                // var problem_arr_index = Math.floor((Math.random()*problem_total));
                var showTime = 2;
                var time = showTime;
                $(document).on('click', function() {
                    time = showTime;
                });
                var interCount = setInterval(function() {
                    time--;
                    if(time == 0) {
                        clearInterval(interCount);
                        var index = $.inArray(player_time, problem_view_ats_list);
                        if(index >= 0){
                          ShowMessage(problem_json[index]["id"]);
                        }
                    }
                }, 1000);
    
                function ShowMessage(problem_id) {
                    player.videoPause();
                    show_problem(problem_id)
                };
    
                function show_problem(problem_id){
              $.ajax({
                  url: "/api/v1/videos/problem/" + problem_id,
                  type: "get",
                  dataType:'json',
                  success: function(result) {
                      console.log('---------------');
                      console.log(result);
                      var htmladd="";
                      var input_type = "checkbox"
                      var problem_type = result["paper_problem"]["problem_type"]
                      if(problem_type == "Single"){
                        input_type = "radio"
                      }
                      htmladd +='<div class="content">';
                      htmladd +='<div class="hide_box" style="display: none;"></div>';
                      htmladd +='<div class="shang_box" style="display: none;">';
                      htmladd +='<div class="shang_tit">';
                      htmladd +='<p>'+ result["paper_problem"]["title"] + '</p>';
                      htmladd +='</div>';
    
                      htmladd +='<div class="problem_order">';
                      htmladd +='<div class="problem_answer">';
                      htmladd += '<p><input type='+input_type+' name="problem_answer" value="A"/> A: '+ result["paper_problem"]["problem_a"] + '</p>';
                      htmladd += '<p><input type='+input_type+' name="problem_answer" value="B"/> B: '+ result["paper_problem"]["problem_b"] + '</p>';
                      htmladd += '<p><input type='+input_type+' name="problem_answer" value="C"/> C: '+ result["paper_problem"]["problem_c"] + '</p>';
                      htmladd += '<p><input type='+input_type+' name="problem_answer" value="D"/> D: '+ result["paper_problem"]["problem_d"] + '</p>';
                      htmladd +='</div>';
                      htmladd +='</div>';
    
                      htmladd +='<div class="order_info" style="display: none;"><p>错误:您选择的答案有误,请重新选择!</p></div>';
                      htmladd +='<div class="shang_payselect">';
                      htmladd +='<button class="btn-common">提交</button>';
                      htmladd +='</div></div></div>';
    
                      $("#problems").append(htmladd);
                      $(".hide_box").fadeToggle();
                      $(".shang_box").fadeToggle();
    
                      $(".btn-common").click(function () {
                          var obj = document.getElementsByName("problem_answer");
                          var check_val = [];
                          for (var i = 0; i < obj.length; i++) {
                              if (obj[i].checked) {
                                  check_val.push(obj[i].value);
                              }
                          }
    
                          problem_answer_list = result["paper_problem"]["problem_answer"].split(",");
                          if (isContained(check_val, problem_answer_list)){
                              $('.hide_box').css('display','block');
                              $('#problems').css('display','block');
                              player.playOrPause();
                              $(".content").load(location.href+" .div")
                          }else {
                              $('.order_info').css('display','block');
                          };
    
                      });
                      $("#problems").show();
                  },
                  error: function(e){
                      console.log(e.status);
                      console.log(e.responseText);
                  }
              });
                }
            }
    
            function settimeFn3(player_time) {
                var showTime = 2;
                var time = showTime;
                $(document).on('click', function() {
                    time = showTime;
                });
                var interCount = setInterval(function() {
                    time--;
                    if(time == 0) {
                        clearInterval(interCount);
                        var index2 = $.inArray(player_time, problem_view_ats_list2);
                        if(index2 >= 0){
                            ShowMessage3();
                        }
                    }
                }, 1000);
    
                function ShowMessage3() {
                    player.videoPause();
                    $('#heihei').css('display','block');
                    $('#problems2').css('display','block');
                };
            }
    
            function isContained (a, b){
                if(!(a instanceof Array) || !(b instanceof Array)) return false;
                if(a.length != b.length) return false;
    
                for(var i = 0, len = b.length; i < len; i++){
                    if(a.indexOf(b[i]) == -1 && b.indexOf(a[i]) == -1) {
                        return false;
                    }
                }
                return true;
            }
    
        </script>
      </body>
    </html>
  • 相关阅读:
    接口的显示实现和隐式实现
    Math.Round和四舍五入
    经典SQL语句大全(转)
    简明添加log4net到项目中
    NAnt学习笔记(3) Properties, Loggers & Listeners
    (转)Groupon前传:从10个月的失败作品修改,1个月找到成功
    Pyramid中如何配置多种URL匹配同一个View
    《IT项目管理》读书笔记(4) —— 项目范围管理
    C#语法糖
    枚举类型转换成字符串
  • 原文地址:https://www.cnblogs.com/rixian/p/13754737.html
Copyright © 2020-2023  润新知