Tuesday, November 20, 2012

How to play a media file in a loop in Windows media player in .net/C#


We can achieve this through:                                                                    // Set the PlayCount property to a big number and normally before the countdown finishes user   // will interact with system definitly                                                          axWindowsMediaPlayer1.settings.playCount = 200000000;                                           // Set the Mode Loop to true                                                                    axWindowsMediaPlayer1.settings.setMode("Loop", true);                                           // in PlayStateChange event, when it is observed that media player state is stopped then play   // is again                                                                                      axWindowsMediaPlayer1.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(axWindowsMediaPlayer1_PlayStateChange);
void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
        {
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsStopped)
            {         
                axWindowsMediaPlayer1.Ctlcontrols.play();
            }
        }

2 comments:

  1. this wont work.
    try this:
    private void timer1_Tick(object sender, EventArgs e)
    {
    // Subtract the current position from the duration of the current media to get
    // the time remaining. Use the Math.floor method to round the result down to the
    // nearest whole number.
    double t = Math.Floor(player.currentMedia.duration - player.Ctlcontrols.currentPosition);
    lenght = player.currentMedia.duration.ToString();
    label2.Text = lenght;
    // Display the time remaining in the current media.
    label1.Text = ("Seconds remaining: " + t.ToString());
    if (player.playState == WMPLib.WMPPlayState.wmppsStopped)
    {
    player.Ctlcontrols.play();
    }
    and write this into playbutton.click:
    timer1.Interval = 1000;
    timer1.Start();

    ReplyDelete