视频观看次数不在移动设备上计算

时间:2018-12-22 20:39:22

标签: laravel html5-video bootstrap-modal

我有一个项目,我在其中计算观看视频的次数。但我注意到,视频观看次数并未在移动设备上计算在内,模式也没有显示,而是视频自动进入全屏状态。我的代码在这里,有人可以看看它在做什么吗?我将添加评论,以便您可以了解发生了什么。

    /*This the video once the video is click it opens to a modal and the 
     video automatically plays.
  */
   <video class="video1" id="cx" preload="auto" align="middle" data- 
   toggle="modal"  data-target="#mymodal" data-user-id="{{$users->id}}"
            data-video-src="{{$users->intro_video}}"
            data-video-views="{{$users->clicks}}" style="  
       cursor:pointer;  "><source  src="{{$users->intro_video}}#t=15" 
      playsinline alt="Video Unavailable"   id="" ></source>
     </video>

   //This the modal
   <div class="container">
<div class="row">
<div class="col-sm-12">
<div id="mymodal" class="modal fade" role="dialog" style="padding- 
 top:3%;">
      <h1 class="close" data-dismiss="modal" style="color:white; 
 position:relative; right:20px;">X</h1>

<div class="modal-dialog">
<!--modal content-->

<div class="modal-content" style="align-items: center;">

<div class="modal-body" style=" height:300px; width:100%; 
 background:black; display:flex; justify-content: center;">
   <video  class="video2" id="video_source" src="" preload="auto" 
 align="middle" style="  
       cursor:pointer;  " autoplay="true">
  </video>
</div>
  </div>

  </div>
</div>
</div>
</div>

  //This is my controller where it will increment the click every time the 
  video is click

 public function index(Request $request){
    $requested_id=$request->input('requested_id');
     $video = User::where('id', $requested_id)->increment('clicks');



   }

//Last but not least this is javascript for the ajax request
once the modal shows the request is going to be sent to increment the video count

$('#mymodal').on('show.bs.modal show', function (event) {

    var button = $(event.relatedTarget);


    var user_id = button.data('user-id') ;
    var video_src = button.data('video-src');
    var video_views = button.data('video-views');


    var modal = $(this);
    modal.find('#video_source').attr('src', video_src);
    modal.find('#video_views').text(video_views);

    // send ajax request to increment video count. Just send request_id
    $.ajax({
        method: 'GET',
        url: 'getmsg',
        dataType: "json",
        contentType: "application/json",
        data : {
            requested_id: user_id
        },
        success: function(data){

        }
    });
})

0 个答案:

没有答案