我用WMPLib获取多媒体文件播放时间时总是0??这是为什么呢。
希望大家能帮帮忙。
 WMPLib.WindowsMediaPlayer wmp = new WindowsMediaPlayer();
        
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.listBox1.SelectedItem != null)
            {
                this.textBox1.Text = this.listBox1.SelectedItem.ToString();
                this.Text = "[" + this.textBox1.Text.Substring(this.textBox1.Text.LastIndexOf("\\") + 1) + "]--精品音乐";
                wmp.URL = this.textBox1.Text;
                //22222
                
                //11111
                
                
                this.label2.Text = wmp.currentMedia.durationString;
                wmp.settings.setMode("loop", true);
                wmp.controls.play();
            }
            else
            {
                this.button1.PerformClick();
            }
        }

解决方案 »

  1.   

    currentMedia.duration参考: Media player控件基本使用 wmplib.dll
      

  2.   

    这个方法我知道,但是获取的是0,希望能发这个属性使用的源码,谢谢,顺便帮我看看,上面的那个程序用什么错误,为什么wmp.currentMedia.durationString;是0???
      

  3.   

    在程序中,刚开始显示结果很可能为0.这时候很可能获取不到文件的播放时间长度,容易出错。
    所以在利用的时候可以加一个timer控件:Private void Timer1_Tick(...)
    {
       if (AxWindowsMediaPlayer1.currentMedia.duration == 0)
          MessageBox.Show('可能因为媒体文件的打开需要一定时间,这里等待媒体文件的打开');
           MessageBox.Show(AxWindowsMediaPlayer1.currentMedia.duration.ToString());
    }此时MessageBox便会显示文件播放长度。