Go
Not registered? Sign up!

Tracking video being clicked/played

Google Translate
9 posts | return to the Setup Problems forum | get the rss feed for this thread

Jul. 09, 2009acer152

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?

Jul. 09, 2009lost

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.

Jul. 09, 2009acer152

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

Jul. 09, 2009acer152

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)

Jul. 09, 2009acer152

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

Jul. 09, 2009lost

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!   grin

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
        }
      };

Jul. 09, 2009acer152

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.

Jul. 09, 2009lost

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/

Nov. 03, 2009Sandip

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.

Add a reaction

You can also return to the category or try this search for related threads.


 

Search the Forums

Go

Support

Support Here are some helpful links to learn more about the JW Player™:

Monetize Your Video

Monetize Your Video Earn money with ads from LongTail's AdSolution. Watch our demos and sign up now!

Why Buy a License?

Why Buy a License? If you don’t buy a commercial license, you cannot use a JW Player™ on (i) a site that has ads; (ii) a corporate site; or a (iii) CMS. Our licenses are very inexpensive, so what are you waiting for? Buy a license today.