Thursday, August 13, 2009

Windows media player end of stream problem

When we were developing a web player for one of our customers, we used the windows media player component. While developing it we found out that the end of stream event is not firing at the end of the play. Finally we came up with this solution.
In here we used the “PlayStateChange” event of the media player in order to detect the end of stream.

bool isMediaEnded = false;
private void mPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{

if (mPlayer.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
{
isMediaEnded = true;
}
else if (mPlayer.playState == WMPLib.WMPPlayState.wmppsTransitioning)
{
if (isMediaEnded)
{
isMediaEnded = false;
// End of stream occurs here. Do what ever you want.

}
}
}