Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

Forums

/

Tracking video being clicked/played

9 replies [Last post]

Is it possible to determine when the movie is played/clicked? I'd like to AJAX some information to my database to track that the video was played. Is there an event that can be used to trigger my Javascript? Or, is there another way to track the play action?

You need to setup a Listener.

See the JavaScript API docs here: http://developer.longtailvideo.com/trac/wiki/FlashApi

and the events docs here: http://developer.longtailvideo.com/trac/wiki/FlashEvents

The ControllerEvent.ITEM index number always changes when a new playlist item is selected by the user or automatically by the player when it advanaces to the next track.

If you need code, I have lots of it, including code for sending stats to the server using JSON. I'd be happy to share the code if you want it.

callback and the links you provided should be fine, thanks.

If you have example of listener for PLAY, that would be great. I get an error that the object does not support the property or method for addControllerListener. Maybe I have older player though (purchased last year)

Also, how do I find out what version of the player I have?

You can find out the player version by right-clicking on the player.

You really should update, many things have changed.

Latest players are here: http://developer.longtailvideo.com/trac/log/trunk/as3/player.swf
Click on the release that you want in the Rev column to download the player.

You have to wait until the player has finished loading and indexing the playlist (an asynchronous event) before you can add Listeners.

I typically do it like this:

    <script type="text/javascript">
      var player    =  null;
      var playlist  =  null;

      function playerReady(obj)
      {
        player = gid(obj.id);
alert('Player ID: ' + player.id);
        addListeners();
      };

      function addListeners()
      {
        playlist = player.getPlaylist();

        if(playlist.length > 0)
        {
alert('Playlist: ' + playlist);
          player.addModelListener('STATE', 'stateMonitor');
        }
        else
        {
alert('Try Again!');
          setTimeout("addListeners();", 100);
        }
      };

      function stateMonitor(obj)
      {
alert('State: ' + obj.newstate);
        if(obj.newstate == 'COMPLETED')
        {
          //...load a new page when the media file completes playing
          window.location = 'http://www.google.com';
        }
      };

      function gid(name)
      {
        return document.getElementById(name);
      };
    </script>

The alerts are just there to annoy you!   :D

A PLAY Listener:

      function addListeners()
      {
        playlist = player.getPlaylist();

        if(playlist.length > 0)
        {
          player.addControllerListener('PLAY', 'playMonitor');
        }
        else
        {
          setTimeout("addListeners();", 100);
        }
      };

      function playMonitor(obj)
      {
alert('Play: ' + obj.state);
        if(obj.state)
        {
          //...do something here
        }
      };

Updating the player seemed to work with the code I have.

Also, I have swfobject 1.4 ... does that need to be upgraded? I tried the most recent swfobject.js, but that appears to have different call to create swfobject than 1.4, and the existing code no longer works ... so rather not update all the code unless necessary.

SWFObject v1.5 works OK.

swfobject v2.2, loaded from Google's CDN is much better, but you do have to re-do your code. It's quite easy; there are many, many examples on the Forum.

Loading from Google AJAX Libraries API

    http://pipwerks.com/journal/2008/11/11/swfobjectjs-finds-a-home-on-google-servers/

How & Why You Should Use Google CDN

    http://webmuch.com/how-why-you-should-use-google-cdn/

Can someone send me the example code of the video play tracking using c#.

You can send me in my email as well sandip dot ghosh at vincentpartners dot com

Thanks in advance to help.

Thanks all, this was a great start to my tracking. How can I track the progress that someone is making in a video. Not just the Play and Complete.

Thanks