1

I have spent a great deal of time searching, and with all different key phrases. I am working on a Media Player and have a menu strip with an option to fast forward and reverse. Here is what I have currently:

private void increaseRateToolStripMenuItem_Click(object sender, System.EventArgs e)
{
    if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPlaying)
    {
        WMPLib.IWMPControls3 controls = (WMPLib.IWMPControls3)axWindowsMediaPlayer1.Ctlcontrols;
        if (controls.get_isAvailable("fastForward"))
        {
            controls.fastForward();
        }
    }
}

Which essentially is the circle that I have been going around. I started here, tinkered, and then ended up back here. It is driving me crazy. In theory it sounds so simple, but I am getting nothing.

The example I used above was off of the MSDN example here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd564741(v=vs.85).aspx

So I am here asking, how can I fast forward (and reverse) the video when the menu item is clicked in C#?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Zac Dibble
  • 23
  • 1
  • 7

1 Answers1

1

This is an extension from my answer on this related question.

According to the OP over there (see comments on my answer) this would work if you're playing an MP4 file, but if you're trying to play an AVI it won't work as they're not indexed. He instead suggested that you increment the currentPosition property (MSDN documentation) to achieve this effect.

So to summarise, instead of controls.fastForward(), try controls.currentPosition += someIncrement in a loop of some sort (perhaps this question might help you achieve this: C# how to loop while mouse button is held down)

Community
  • 1
  • 1
Bridge
  • 29,818
  • 9
  • 60
  • 82
  • I tried to tie in a loop with a check box checked being true, leading it to jump straight to the end and then crash hard. I'm still a newbie, so I am picking things up as I go. Here is what I used: 'while (increaseRateToolStripMenuItem.Checked == true) { controls.currentPosition += 1; }' I feel as if the +=1 is completely wrong. – Zac Dibble Aug 30 '12 at 09:28
  • @ZacDibble The `+=1` just increments the position by one second - could use `controls.currentPosition++;` if it makes you feel any better! It might throw an Exception once it reaches the end of the video (and you try to set the position to a time that doesn't exist) - might need to put a check in for that. Where did you put this code? – Bridge Aug 30 '12 at 09:41
  • The code I am currently looking at is this: 'while (increaseRateToolStripMenuItem.Checked == true) { controls.currentPosition += 1.0; if (increaseRateToolStripMenuItem.Checked == false) { break; } }' I am still swapping in, out and around. – Zac Dibble Aug 30 '12 at 09:55
  • @ZacDibble But where have you put that code? If your code is being executed on the UI thread your app will probably become unresponsive, and you won't be able to uncheck the tickbox - it'll run until you overrun the length of the video, and you'll get the exception I mentioned. Try one of the approaches in my last link to get a way of looping whilst not blocking your UI thread! – Bridge Aug 30 '12 at 09:58
  • Sorry it took me so long to respond, I've been incredibly busy. But I ended up coming to a solid resolution. I'll put the code in my original post if you're interested, or in case anyone else needs the same answer I did. – Zac Dibble Sep 03 '12 at 07:49