Last Updated: February 25, 2016
·
1.342K
· Dirty Bird

Windows Media Player Events FrameWork

The most basic problem with developer who are still stick to window media player as there Video content delivery is the way its events work.

Windows media player events are basically the enums.Starting from 0 to 12
Where

case 0:  "Undefined"

case 1:   "Stopped";

case 2:   "Paused";
    .
    .
    .
case 11:  "Reconnecting"

case 12 :  "Last"

and so on.At many occasion developer don't event realize how to use them.

So here i am .I was in same kind of difficulty when i need a solution to my player which was using IE object to display a web player in Windows screen saver.

The obvious choice was to use JWplayer.And initially we did get success .Running JWplayer in screen saver was quite fun,but there was a problem.

The problem was that once the JWplayer content is cached ,it never runs.actually it started to give javascript error.

I don't remember what that error was and till date i can't find the reason behind it,but most probably the reason was the object of IE6 that we were using for running JWplayer in screensaver.

So what was the solution.keeping the code as it is but using different player.so which player can be best suitable for IE instance ,not surprising WMV(Windows media player)

So here i am sharing the code that i written for my Windows media player.JWplayer like framework for Windows media player.

code

var WMPlayer={

isFullScreen: "",

cnt: 0,

setup: function (options) {

    player = document.getElementById('contentPlayer');

    this.isFullScreen = options.fullScreen;

    player.URl = options.file;

    player.settings.autoStart = options.autostart;

    player.height = options.height;

    player.width = options.width;

    if (player.settings.autoStart == true) {
        player.controls.play();
    }
    if (options.controls == false) {
        this.HideControls();
    }

},

HideControls: function () {
   // player.uiMode = "none";
},

FullScreen: function (bool) {
   // player.fullScreen = bool;
},

Pause: function () {
 //   player.controls.pause();
},

Play: function () {
 //   player.controls.play();
},

Playing: function () {
 //     writing code like do we need to make player fullscreen once it start playing
},

Ready: function () {
   //    DO something when player is ready to play
},

Time: function () {

    clearInterval(playPauseInterval);

    //    There is not Time Event in WMVPlayer so we need to figure it out by using javascript interval
    playPauseInterval = setInterval(function () {

           var playerCurrentDuration = player.controls.currentPosition;

    }, 100);
  }
}

No not the code alone.we need to setup wmvplayer core events to call our events.

object(type='video/x-ms-wmv',id='contentPlaye'r,CLSID:'6BF52A52-394A-11d3-B153-00C04F79FAA6' )
param(name='wmode',value='trasparent')
param(name='stretchToFi't,value='true')
param(name='autoStart',value='false')


script(type='text/javascript', for=.contentPlayer' ,event='playStateChange').

    if (player != null) {
        if (player.playState == 3) {
            WMPlayer.Playing();
            clearInterval(pauseInt);
            WMPlayer.Time();
        }

        if (player.playState == 8) {
            clearInterval(pauseIntervalWMPlayer);
            cnt = 0;
            nextPausecnt = 0
        }

        if (player.playState == 10) {
            WMPlayer.Ready();
        }
    }

Getting Started by calling WMPlayer instance setup method.

WMPlayer.setup({
      autostart: true,
      file: URL,
      height: h,
      width: w,
      fullScreen: paramFullScreen,
      controls: false
  });