-1

What I tried to was getting the value in the following way, which didn't work:

private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
    TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal);
    axWindowsMediaPlayer1.Ctlcontrols.play();
    axWindowsMediaPlayer1.Ctlcontrols.currentItem =
                axWindowsMediaPlayer1.currentPlaylist.Item[listBox1.SelectedIndex];
    backgroundWorker2.RunWorkerAsync();
}

private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
{
    double val = 100*axWindowsMediaPlayer1.Ctlcontrols.currentPosition/axWindowsMediaPlayer1.currentMedia.duration;
    TaskbarManager.Instance.SetProgressValue((int)val,100);
}

I am also not sure, where would I put the line for stopping the progress, but I guess it is a bit early to think about it, since I can't get the progress to work anyway.

Is the problem in how I used the backgroundWorker or in how I update the value, or something else?

Thanks in advance,

~~hlfrmn

EDIT:

private void TaskbarProgressValueDeterminator()
    {
        TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal);
        while (axWindowsMediaPlayer1.Ctlcontrols.currentPosition < axWindowsMediaPlayer1.currentMedia.duration)
        {
            TaskbarManager.Instance.SetProgressValue((int)(100 * axWindowsMediaPlayer1.Ctlcontrols.currentPosition / axWindowsMediaPlayer1.currentMedia.duration), 100);
        }
        TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress);
    }
Marian
  • 3,789
  • 2
  • 26
  • 36

1 Answers1

1

The background worker will update the progress only once. I expect you need to put in a while loop or a timer to update the progress repeatedly while the track is playing.

Glen Thomas
  • 10,190
  • 5
  • 33
  • 65
  • After putting the SetProgressValue into a loop, nothing happens still. By the way, I have no idea what I was thinking when I wrote the initial code an hour ago. By the looks of it I was pretty sure that the "val" is volatile and the backgroundWorker2 is autolooping. I decided against using the feature at all for now, but thank you for noticing the faults in the code. – Marian Sep 02 '15 at 23:36