2

我使用 WMPLib 在 C# 中制作一个简单的 mp3 播放器。我几乎完成了,但还有一件事我想做。

我想知道这首歌走了多远,也想知道这首歌还剩下多少。使用例如进度条。

谢谢

亚当

4

2 回答 2

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);
}
于 2011-12-19T01:51:11.570 回答
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 = "";

    }

并且不要忘记在您的项目表单中添加一个 Timer 并将 Sound_Progress(your ToolStripStatusLabel, your ToolStripProgressBar) 放入您的 Timer_Tick() Event 中。

谢谢 !

于 2015-01-23T02:20:46.147 回答