2009-12-09 64 views
1

使用WMPLib在C#中制作一个简单的mp3player。我几乎完成了,但还有一件事我想做。C#WMPLib mp3的持续时间

我想这首歌有多远,而且这首歌还剩多少。 使用例如进度条。

感谢

亚当

+0

你介意说这个程序是干什么的? =) – Marcelo 2009-12-09 19:44:52

+0

现在它的播放文件支持WMPLIb:P但我无法弄清楚如何让进度条一次移动一秒:P – 2009-12-09 21:07:35

回答

1
private void timer1_Tick(object sender, EventArgs e) 
{ 
    double percent = 0; 
    if (mp.Length != 0) 
    percent = ((double) wplayer.controls.currentPosition/wplayer.controls.currentItem.duration); 
    progressBar1.Value = (int)(percent * progressBar1.Maximum); 
} 
0

我有一个想法,只是试图StatusStrip中添加到您的项目表格,并尝试将ToolStripStatusLabel和ToolStripProgressBar添加到它,然后你可以使用这个简单的代码,它的工作原理100%:

public void Sound_Progress(ToolStripStatusLabel l1, ToolStripProgressBar psb) 
    { 
     //NASSIM LOUCHANI 


      int i = Convert.ToInt32(Player.controls.currentItem.duration); 
      int j = Convert.ToInt32(Player.controls.currentPosition); 
      int Defrence = (i-j); 
      l1.Text = Player.controls.currentPositionString + " | " + Player.controls.currentItem.durationString; 

      psb.Maximum = i; 
      psb.Minimum = 0; 

      if (Defrence == i) 
       psb.Value = i; 
      else if (Defrence != i) 
       psb.Value = Defrence; 
      else if (Defrence == 0) 
       l1.Text = ""; 

    } 

而且不要忘了一个定时器添加到您的项目表格并把Sound_Progress(你ToolStripStatusLabel,你ToolStripProgressBar )到您的Timer_Tick()事件中。

谢谢!