silverlightsilverlight-toolkit

Silverlight play,pause and resume events


I am using silverlight player in our project. It is working well. These days I was loking for silverlight events becasue I will send some information to google analytics on player pause,resume and play events. I checked lots of article. Unfortunately there is no information about these events. All articles give the same example and same events.(onError and onLoad events). How can I add play,pause and resume events in javascript? Please check below javascript code.

          Silverlight.createObject("XXXXXXXXX",player.get(0),"xxPlayer",
                                  {
                                    width: playerWidth + "", height: playerHeight + "", background: "black"version: "4.0.60310.0",enableHtmlAccess: true'},
                                                       { onError: onSilverlightError, onLoad: null },
                                                       extra, "context");

Solution

  • There is a general purpose CurrentStateChanged event which returns the current state of the media (playing, stopped, etc.)

    MediaElement events

    To access the events you need something like this:

    player = sender.findName("ObjectName");
    var stateChangedToken = player.addEventListener("CurrentStateChanged", onCurrentStateChanged);
    

    Then you can fill out the onCurrentStateChanged JavaScript to do what you want.

    Handling Silverlight events in JavaScript (MSDN)