A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: MediaPlayer - ExternalInterface.call - analytics

  1. #1
    Senior Member
    Join Date
    Dec 2010
    Posts
    111

    Smile MediaPlayer - ExternalInterface.call - analytics

    Hi!

    I managed to get Google analytics working on button clicks in koolmoves.

    But what I now want to know is how to get it working on media player events.

    this is how I got it working for a button named 'about' :


    -----------------

    about.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    function mouseDownHandler(event:MouseEvent):void {
    ExternalInterface.call("pageTracker._trackPageview ",
    "/about");
    }

    -------------------

    It sends data to google analytics with the title "/about"


    How can I also do this with media player events? my knowledge of AS3 is limited to cutting in pasting. I looked in the 'mediaPlayer API.txt' in API koolmoves folder, and I am still confused.


    I want flash event data to send on these events:

    -what item in playlist is played
    -if item is stopped
    -if item is completed

    Cool thing about google analytics is that is gives a duration of time for each event (events are listed as 'pages'). So then I also know exactly what time during an mp3 or video someone has stopped it.

    This is general information I would love to know, because I can also apply it to other analytics software.


    any help would be appreciated

    Dave

  2. #2
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Events

    mediaplayer.addEventListener("itemLoad", itemLoadHandler); // item starts loading
    mediaplayer.addEventListener("itemComplete", itemCompleteHandler); // item finished
    mediaplayer.btnStop.addEventListener("click", stopClickedHandler); // stop clicked

    Selected item in playlist

    mediaplayer.playlist.selectedItem

  3. #3
    Senior Member
    Join Date
    Dec 2010
    Posts
    111

    still no joy

    I must be doing something wrong.

    IN this example, I can get flash to send a function to Javascript with buttons events, but not with a mediaplayer event (the analytics software is now Woopra, not Google Analytics but its the same).




    for functions 'MediaPlay' and 'MediaStop' - it WORKS with button events:

    -------------------AS3 with buttons ------------



    woopra4.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler5);
    function mouseDownHandler5(event:MouseEvent):void {
    ExternalInterface.call("MediaPlay");
    }

    woopra5.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler6);
    function mouseDownHandler6(event:MouseEvent):void {
    ExternalInterface.call("MediaStop");
    }


    ----------------------

    but with Media Player events, it is NOT WORKING. What am I doing wrong?



    ---------------------------AS3 media player events


    mediaplayer.addEventListener("itemLoad", itemLoadHandler);
    function itemLoadHandler(){
    ExternalInterface.call("MediaPlay");
    }

    mediaplayer.btnStop.addEventListener("click", stopClickedHandler);
    function stopClickedHandler(){
    ExternalInterface.call("MediaStop");
    }


    ----------------------------


    cheers

    Ben

  4. #4
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Most likely the problem is that your listener functions don't take an argument.
    Try this ...

    mediaplayer.addEventListener("itemLoad", itemLoadHandler);
    function itemLoadHandler(e:Event){
    ExternalInterface.call("MediaPlay");
    }

    mediaplayer.btnStop.addEventListener("click", stopClickedHandler);
    function stopClickedHandler(e:Event){
    ExternalInterface.call("MediaStop");
    }

  5. #5
    Senior Member
    Join Date
    Dec 2010
    Posts
    111
    thanks, that did the trick


    now for the tricky part

    how can I use this:

    mediaplayer.playlist.selectedItem


    to send a variable of what item no. is selected?

    cheers

  6. #6
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    For the selected index you can use

    mediaplayer.playlist.selectedIndex

    mediaplayer.playlist.addEventListener("change", playlistChangeHandler);
    function playlistChangeHandler(e:Event){
    var idx:int = mediaplayer.playlist.selectedIndex;
    }

  7. #7
    Senior Member
    Join Date
    Dec 2010
    Posts
    111
    great that worked!

    would I be too ambitious to ask if there is a function to send the actual name of playlist item instead of just index number?

    so send a variable of the playlist item name via externalinterface.call??

    thanks heaps

  8. #8
    Senior Member
    Join Date
    Dec 2010
    Posts
    111
    I read the API and figured the name of each item is called 'label',

    so I took a wild guess and tried this:

    ---------------

    mediaplayer.playlist.addEventListener("change", playlistChangeHandler);
    function playlistChangeHandler(e:Event){
    var idx:int = mediaplayer.playlist.selectedIndex;
    var lbl:int = mediaplayer.playlist.selectedLabel;
    ExternalInterface.call("Song", idx, lbl);
    }


    ----------------


    But it did not work

  9. #9
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    Did you read the AS3 API docs ?
    You can pop them up by clicking a button in the actionscript editor.

    I think it should be

    var lbl:String = mediaplayer.playlist.selectedItem.label;

  10. #10
    Senior Member
    Join Date
    Dec 2010
    Posts
    111
    nope, did not work.

    I was wrong, it must not be 'label'

    so this is not understood by koolmoves:

    mediaplayer.playlist.selectedItem.label


    in the API, it says:

    "playlistfile : external file containing the playlist. Each line contains one item
    in the format: label | value"

    so maybe that just applies to the xml.



    but maybe I am missing something....I cannot understand the API properly, or the drop down list in KoolMoves actionscript editor


    my knowledge of AS3 is useless.....I do not understand the syntax or semantics

    I am a music composer, not a web developer.... so just trying a fast and easy way to have the music that is played online sent to analytics database. I have figured out the javascript end so far, just not this part

    is there a function to send the name of mediaplayer item label?


    cheers

  11. #11
    Senior Member
    Join Date
    Dec 2010
    Posts
    111
    I have tried these versions:

    --------

    mediaplayer.playlist.addEventListener("change", playlistChangeHandler);
    function playlistChangeHandler(e:Event){
    var idx:int = mediaplayer.playlist.selectedIndex;
    var lbl:String = mediaplayer.playlist.selectedItem.label;
    ExternalInterface.call("Song", idx, ido);
    }

    ----------------------------

    mediaplayer.playlist.addEventListener("change", playlistChangeHandler);
    function playlistChangeHandler(e:Event){
    var idx:int = mediaplayer.playlist.selectedIndex;
    var lbl:String = mediaplayer.playlist.selectedItem.name;
    ExternalInterface.call("Song", idx, ido);
    }

    -------------------------

    mediaplayer.playlist.addEventListener("change", playlistChangeHandler);
    function playlistChangeHandler(e:Event){
    var idx:int = mediaplayer.playlist.selectedIndex;
    var lbl:String = mediaplayer.playlist.selectedItem.overlay;
    ExternalInterface.call("Song", idx, ido);
    }

    -----------------------

    mediaplayer.playlist.addEventListener("change", playlistChangeHandler);
    function playlistChangeHandler(e:Event){
    var idx:int = mediaplayer.playlist.selectedIndex;
    var lbl:String = mediaplayer.playlist.selectedItem.listItem;
    ExternalInterface.call("Song", idx, ido);
    }

    ----------------------

    mediaplayer.playlist.addEventListener("change", playlistChangeHandler);
    function playlistChangeHandler(e:Event){
    var idx:int = mediaplayer.playlist.selectedIndex;
    var lbl:String = mediaplayer.playlist.selectedItem;
    ExternalInterface.call("Song", idx, ido);
    }

    ----------------------


    NONE WORK

    is there a wrong context?

    or is it not possible? or is it a bug?


    cheers

  12. #12
    Senior Member
    Join Date
    Dec 2010
    Posts
    111
    ooops just realised I had an error with the variable naming...

    re-testing now

  13. #13
    Senior Member
    Join Date
    Dec 2010
    Posts
    111
    YESSSSSSSSSSS


    you were right the first time

    thanks so much for your help!!

    YOU ROCK!!!


    Have a Happy New Year

  14. #14
    Senior Member
    Join Date
    Dec 2010
    Posts
    111
    Hi W.Brants

    actually the mediaplayer 'item complete' is not working


    this is the code I used

    -----------------

    mediaplayer.addEventListener("itemComplete", itemCompleteHandler);
    function itemCompleteHandler(e:Event){
    var idx:int = mediaplayer.playlist.selectedIndex;
    var lbl:String = mediaplayer.playlist.selectedItem.label;
    ExternalInterface.call("MediaComplete", idx, lbl);
    }

    ---------------------


    is there something that maybe goes after the addEventListener bit?


    cheers

    D

  15. #15
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    It looks fine to me.

    It often helps to use a debug version of the Flash Player and a viewer to view its log file.
    The error messages it logs can make solving problems much easier.
    Eric has written something about it http://etuom.blogspot.com/search/lab...20Log%20Viewer

  16. #16
    Senior Member
    Join Date
    Dec 2010
    Posts
    111
    got it working

    I had uploaded the wrong swf to the server.. silly me


    thanks once again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center