0

我正在使用 listBox 在表单上使用 axWindowsMediaPlayer 播放媒体文件,在该表单中,下一个媒体在我使用了计时器的时间间隔后播放。现在我想在屏幕上显示该时间间隔的倒数计时器。如何做this..plz help.我如何在媒体端使用计时器的代码是:

   System.Timers.Timer _timer = new System.Timers.Timer();
    object _locker = new object();
     Player.PlayStateChange += Player_PlayStateChange;

        _timer.Elapsed += _timer_Elapsed;
        _timer.Interval = 3000;
    void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {

        _timer.Stop();
        lock (_locker)
        {
            this.Invoke((MethodInvoker)delegate
        {
            if (listBox2.SelectedIndex + 1 < listBox2.Items.Count)
            {

                listBox2.SelectedItem = listBox2.Items[listBox2.SelectedIndex + 1];
            }
        });
        }
    }

    void Player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
    {
        if ((WMPLib.WMPPlayState)e.newState == WMPLib.WMPPlayState.wmppsMediaEnded)
        {
               _timer.Start();


        }
        else if ((WMPLib.WMPPlayState)e.newState == WMPLib.WMPPlayState.wmppsReady)
        {

                Player.Ctlcontrols.play();


        }
    }  
4

2 回答 2

0

只需在 _timer_Elapsed() 中放入一个计数器

private int m_counter=0;

将每个媒体设为 0(让我们在媒体开始后说)

并创建一个标签来显示 counter.ToString()

于 2013-01-17T07:13:14.997 回答
0
    private  int totalwaittime = 5;
    private  int counter = 0;
    private static void OnTimer(object sender, ElapsedEventArgs elapsedEventArgs)
    {
        counter++;
        Label1.text = String.Format("Time Left : {0}", totalwaittime - counter);
        if (totalwaittime - counter == 0)
        {
            timer.Enabled = false;
            //play next file
        }
    }

    void Player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
    {
        if ((WMPLib.WMPPlayState)e.newState == WMPLib.WMPPlayState.wmppsMediaEnded)
        {
            counter = 0;
            timer.Enabled = true;


        }
        else if ((WMPLib.WMPPlayState)e.newState == WMPLib.WMPPlayState.wmppsReady)
        {

            Player.Ctlcontrols.play();


        }
    }
于 2013-01-17T07:13:44.973 回答