0

I am streaming videos to student but i am using media based server which is costly. and charge for every time i play my video. so i want to limit my user to watch only to time any of videos. but how would i know that this video is completely played or not. and how do i count them to you have reached your limit.

 <div class="videoContainer" >
          <!-- <center> -->
          <video id=example-video data-setup='{"liveui": <?= $live ?>}'  class="video-js vjs-default-skin vjs-liveui vjs-big-play-centered"  controls preload="true" poster='{{$content_poster_image_path}}'></video>
         
          <link href="https://vjs.zencdn.net/7.6.6/video-js.css" rel="stylesheet" />
          <link href="{{themes('node_modules/videojs-seek-buttons/dist/videojs-seek-buttons.css')}}" rel="stylesheet" />
          <!-- <script src="https://vjs.zencdn.net/ie8/1.1.2/videojs-ie8.min.js"></script> -->
          <script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.15.0/videojs-contrib-hls.min.js"></script>
          <script src="{{themes('node_modules/videojs-watermark/dist/videojs-watermark.js')}}"></script>
          <script src="{{themes('node_modules/@filmgardi/videojs-controls-badge/dist/videojs-controls-badge.js')}}"></script>
          <script src="{{themes('node_modules/videojs-seek-buttons/dist/videojs-seek-buttons.min.js')}}"></script>
           <script src="{{themes('node_modules/videojs-ppslides/dist/videojs-ppslides.min.js')}}"></script>
           <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/videojs-overlay/1.1.4/videojs-overlay.min.js"></script>
           <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/videojs-overlay/1.1.4/videojs-overlay.css">

          
          <script>

          var URL = this.window.URL || this.window.webkitURL;
          var file = new Blob(['{{$video_url}}'],
              {"type" : "video\/mp4"});
          var value = URL.createObjectURL(file);
          // const badgeConf = {
          //       volume: true,
          //       subtitle: true,
          //       quality: true
          //   };

          var player = videojs('example-video',{
            liveui: '{{$live}}',
            responsive:'true',
            autoplay: 'true',
            sources: [{
              src: '{{$video_url}}',
              type: '{{$video_type}}'
            }

            ]
          });
        
          
           player.watermark({
                 image: "{{IMAGE_PATH_SETTINGS.'uFgmieoLC2pR437.png'}}",
                 url: 'http://alphaxyz.com',
                 width:100,
                 xpos: 0,
                 ypos: 0,
                 xrepeat: 0,
                 opacity: 1
             });
          player.ppslides();
          player.seekButtons({
            forward: 30,
            back: 10
          });
          // player.controlsBadge(badgeConf);
          player.play();

          /* ADD Chat button */
          </script>
Prahsant Sharma
  • 371
  • 4
  • 13
  • I wouldn't count how many times user watched the video, but how many times the user opened the page where the video is at.... and log it in db table.... and if the number is greater than 2 show the message you want. – lewis4u May 22 '20 at 06:10
  • You can use videoJs ended event to check when the user completed the video and then do an Ajax call to your Backend to increment your view counter. https://docs.videojs.com/docs/api/player.html#Eventsended – Christophe Hubert May 22 '20 at 06:16
  • @lewis4u but that will count only page visit whether user played or not it will just work as visitor counter, i think Christophe point will work at this point. well thanks to both of you. – Prahsant Sharma May 22 '20 at 06:53
  • The truth is... this is a very tricky thing... what if the user never watches the video till the end? – lewis4u May 22 '20 at 07:01
  • but if he pressed play button and video played to its full playable time then it will count as 1 now if he is turned off his eye while this it will count as 1 – Prahsant Sharma May 22 '20 at 07:07
  • What does that mean: `"...if he is turned off his eye while this..."` ? – lewis4u May 22 '20 at 10:30
  • means i can logically can not find that user has viewed or not, but i can count user has played or not so if he plays the video to the end it will count as 1. as you told it is tricky so i am trying to explain my requirement.@lewis4u – Prahsant Sharma May 22 '20 at 10:44
  • 1
    i find a solution to this at https://stackoverflow.com/questions/37293834/how-to-check-a-user-watched-the-full-video-in-html5-video-player – Prahsant Sharma May 22 '20 at 11:23

0 Answers0