12

I teach an online course, and I need to make sure my students actually watch a certain video. Now, I understand that everything can be defeated, but what I'm looking is the 80/20 rule were I can make a few tweaks to start on the journey of accountability for my students.

Q1: Is there a way via JavaScript to fire an event if the current window loses focus?

Q2: Is there a way to fire an event when the video finishes playing?

Q3: Is there a way to make sure the video was played all the way through instead of the student clicking on the end of the timeline?

I feel compelled to say (again), please don't answer this questions with something like "you're wasting your time, the students will defeat anything that you do".

Phillip Senn
  • 46,771
  • 90
  • 257
  • 373
  • 4
    The answer to your first question is well documented on Stack Overflow: http://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active However, consider that some folks (such as myself) take notes on a computer, and can have more than one window up at a time. I would put your video on my second monitor, and would take notes on my other. If you looked at the focus status, you might get a skewed view of what was really happening. – Brad Oct 05 '12 at 19:59
  • 2
    What type of video player are you using? HTML5 video tag? Flash video? There are video events that you can monitor, but they are different depending upon what type of video is playing. – jfriend00 Oct 05 '12 at 20:00
  • 1
    I guess the usual way to make sure that they had viewed (and understood) the video would be to quiz them on the content. I know it sounds like I'm pointing out the obvious, but it seems like a much, much better solution than trying to wrangle the UA into babysitting them. Is there some reason this approach won't work for the material in the video? – Dagg Nabbit Oct 05 '12 at 20:21
  • +1 GGG - Thats kind of what I was thinking... – Mikey G Oct 05 '12 at 20:23
  • GGG: The video is the same for all students, so a student could copy/paste the answer. – Phillip Senn Oct 05 '12 at 20:26
  • @Phillip so I guess this is meant as more of an "attendance" thing... still, maybe your course management software can hide their replies from each other until the deadline? I know you don't want to hear about the students defeating the system, but it would be so trivial to circumvent that you really wouldn't be able to have any confidence in it at all... might as well just use the honor system. – Dagg Nabbit Oct 05 '12 at 20:34
  • Let them fail if they don't watch the video. If they still pass the course, then they obviously didn't need to watch the video. I'm sorry that i'm probably a little biased, being a college student myself, but when my teachers try to get me to do something (like come to every class), i don't really get it. I pay the teacher to teach me a subject, yet I'm graded on something completely unrelated? If i choose not to listen, that's entirely up to me. Whether i understand the material or not will be determined by my grade in the course. – Mikey G Oct 05 '12 at 20:59
  • Mikey: I sort of agree with you, but I think the majority of people who don't come to class are less-than-average. I've come to the conclusion over the years that controlling your body and making it do your bidding (get out of bed and come to class in the morning), is the beginning of wisdom. – Phillip Senn Oct 08 '12 at 17:37

6 Answers6

9

What is the player you are using. If you are using open source video players like JWPlayer or Flow Player. You can track events. I personally prefer flow player and you can use google analytics to track the duration and any other task you want on the page.

as you have an authentication mechanism on the page you can get the username of the student (or an identifier). Push events to google analytic with this as a label and you can track each and everything the student do including the links he clicked, duration what played, when he played ...

example setup

        <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', '#########']);
      _gaq.push(['_trackPageview']);
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

      })();

    </script>

To track

_gaq.push(['_trackEvent', 'Videos', 'Play', 'Gone With the Wind']);

this is part of the live code i took from http://vsp.ideawide.com/ in which I track some of those events.

var events = {
    clip : {
        onStart: function(clip) {
            _gaq.push(['_trackEvent',"Videos", "Play", defaults.source]);
        },


        onPause: function(clip) {
            _gaq.push(['_trackEvent',"Videos", "Pause", defaults.source, parseInt(this.getTime())]);
        },

        onResume: function(clip) {
            _gaq.push(['_trackEvent',"Videos", "Resume", defaults.source, parseInt(this.getTime())]);
        },

        onSeek: function(clip) {
            _gaq.push(['_trackEvent',"Videos", "Seek", defaults.source ]);
        },

        onStop: function(clip) {
            _gaq.push(['_trackEvent',"Videos", "Stop", defaults.source, parseInt(this.getTime())]);
        },
         onFinish: function(clip) {
            _gaq.push(['_trackEvent',"Videos", "Finish", defaults.source]);
        }
    },
    onFullscreen: function() {
        _gaq.push(['_trackEvent',"Videos", "Full Screen", defaults.source]);
    },
    onError: function(errorCode , errorMessage) {
        _gaq.push(['_trackEvent',"Videos", "Error", defaults.source, errorCode ]);
    }
}

As a final note with analytic properly setup with a proper player you can improve your 80/20 to 99/1.

udnisap
  • 899
  • 1
  • 10
  • 19
3

This is assuming HTML5 video using the video tag.

player = document.getElementById("player");

//Get current percent complete. You may want to check for 95%+ rather than 100%.
setInterval(function(){
    percentComplete = player.currentTime/player.duration;
}, 300); 

window.onblur = function() {
//this will be called when the window loses focus
};

You can call the video tag without the controls attribute to disable the seek bar. You can then trigger play on click using the following:

player.play();
Dcullen
  • 669
  • 4
  • 11
  • I think I heard of a JavaScript event that fires only if the user has the screen in focus. This is now being used especially for mobile so that things don't run the battery down. It's a long word that begins with p from what I can remember. – Phillip Senn Oct 05 '12 at 20:08
  • There is something called the Page visibility API that has been proposed (and implemented on the modern browsers). Was this what you were thinking of? http://davidwalsh.name/page-visibility – Dcullen Oct 05 '12 at 20:14
3

Problems with the initial approach

I teach an online course, and I need to make sure my students actually watch a certain video.

Here's the issue. Your requirement is that students actually watch a video, but the best we can do programmatically is make sure that a video was sent by a server and received by a client. Aside from using extreme measures like facial recognition and audio loopback, you can't be sure that anyone is watching it, or that the intended viewer is watching it, or that anyone is listening. The student can simply start the video and walk away.

That might sound like a technicality, but really it's an important distinction. What you've got is the equivalent of a system designed to make sure someone reads a book, but all the system can do is check whether the book is open or closed at any given time.

Security

Now, I understand that everything can be defeated, but what I'm looking is the 80/20 rule were I can make a few tweaks to start on the journey of accountability for my students.

Everything can be defeated with enough effort, but the proposed solution can be defeated almost effortlessly. If it's easier for your average user to cheat the system than to use it legitimately, it's probably not worth implementing.

An alternative approach

Instead of focusing on whether the browser is running the video, consider shifting focus back to the user. By requiring some specific user interaction while the video is being displayed, you'll be able to have a much higher level of confidence in the system.

The simplest way to do this would be to split the video up into several small parts, displaying a link to the next video after each one plays.

You could then write a small script to show the time between requests for that series of videos (per user), and flag any requests that were too far apart or too close together given the length of the segments (or compared to the average if that data isn't available for some reason). You can pull this data right from the server logs if you have access to them, or you can record it yourself.

Comprehension

If you want to go the extra step and test comprehension (or retention), this alternative approach would be simple to extend. Instead of having one link to the next video, have several links to it, in the form of answers to a question. If you're worried about students sharing the answers, don't tell them whether they got it right, just send them to the next video. You can look at this data later and decide whether you want to use it and how you want to curve it.

Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141
  • 1
    This is not exactly the answer you were asking for, but hopefully it will inspire you ;) – Dagg Nabbit Oct 05 '12 at 22:20
  • Requiring some specific user interaction while the video is being displayed. Interesting idea. – Phillip Senn Oct 08 '12 at 17:39
  • several links to it, in the form of answers to a question. Interesting idea. – Phillip Senn Oct 08 '12 at 17:39
  • Like a captcha à la "Are you still there, then select all tomatos on the screen" :) Nice idea, seriously. Of course, the attention captcha should be related to the video content in best case. --- Another idea I just got: Track the mouse movement during the video, as one indicator if the student is still there. – Avatar Jun 22 '17 at 09:13
1

Maybe do a setTimeout for the length of the video and fire an event once the length of the video has passed.

Try this to detect when the window loses focus:

window.onblur = function() {
   //do something here...
};

If you're really worried about the accuracy of setTimeout, maybe try this:

var start = (new Date).getTime();

function CheckTime() {

   var diff = (new Date).getTime() - start;
   if (diff >= videoLength) {
       FireVideoDoneEvent();
   }
   else {
       setTimeout(function() {
           CheckTime();
       }, 1000);
   }

}
Mikey G
  • 3,473
  • 1
  • 22
  • 27
  • 1
    This... is not a good answer. You don't know how long the video *really* is. Plus, timeout isn't all that accurate. If checking play status is the only way to do it, it would be better to set an interval every couple seconds and check play status and position. – Brad Oct 05 '12 at 20:00
  • Why wouldn't you know how long the video really is? I guess i had no idea how inaccurate setTimeout is for a large time. This article talks about how to create a more accurate timer http://www.sitepoint.com/creating-accurate-timers-in-javascript/ – Mikey G Oct 05 '12 at 20:14
1

Q1: look for event onblur

Q2: that would depend on your player. There are flash video players you can call a javascript function with ExternalInterface.call("myFunctionName()"); from AS3

Q3: I would try to find a flash player that has all that options but my solution is more as3 to javascript.

I hope this may help you!

PbxMan
  • 7,525
  • 1
  • 36
  • 40
1
  1. handle window.onblur, as mentioned
  2. you'll get the 'ended' event fire when video is done
  3. you can call mediaElement.played.end() to get # of secs played in browser.

See here and here

enhzflep
  • 12,927
  • 2
  • 32
  • 51