Subsequent "rewind" and play of video clip fails

Mar 2, 2012 at 11:50 PM

I'm using a MediaUriElement to have a little video file player in my WPF app.

I have a window that opens and it automatically starts playing a clip. There is also a button for replaying the clip which has this for a click handler:

      private void btnReplay_Click(object sender, RoutedEventArgs e)
         meVideoPlayer.MediaPosition = 0;

This works, but only the first time it is clicked. Subsequent presses don't do anything. Is there a bug in the MediaUriElement?

Mar 3, 2012 at 12:09 AM

Here's something interesting about this bug. The first time the above click handler is run, the MediaPosition is reported as the end time of my clip, 27366 something something. I let the clip play through to the end and click again. The second time MediaPosition is 0. Something foul afoot?

Mar 3, 2012 at 10:02 AM

I see that in my own code using MediaKit (written quite a while ago) I had this comment which said that assigning zero to MediaPosition does not enable replay for *some* formats.  In my code I assign it to a number which equates to roughly 0.5s -- nobody will really notice that you're not starting from the very absolute beginning -- but you can try using 1.

I can't remember why I did that or what formats didn't work with a zero.  It also contains a comment that says, again for *some* formats, playing a second time works but playing the third time will always fail.  Unfortunately I couldn't remember whether I actually found out the reason.

Go figure...

- Stephen

Mar 5, 2012 at 6:43 PM

Hi Stephen,

I'm definitely getting the "third time the fail" bug with rewinding my media. Setting the MediaPosition to a non zero value doesn't seem to help either. I'm using an AVI file. I tried using a WMV but this format won't play on stock XP which my company's software unfortunately needs to target. 


Mar 6, 2012 at 2:51 PM
Edited Mar 6, 2012 at 2:55 PM

Sorry, I don't think I've figured out what's causing the third-time-fail bug.

I think this problem is format-specific.  Why can't you play WMV's on XP?  I am pretty sure XP can play WMV's.

Try out other formats (MOV, MPEG-1, MP4, VP6 etc.) and you may find one that enables playing more than 2 times.

If you did trace it out, let us all know!

Mar 6, 2012 at 5:13 PM

The WMV issue is with the video codec that Windows 7 uses to compress video in Windows Live Movie Maker. This codec (VP1 I think? could be wrong) isn't available in stock XP. The user has to download the very latest Windows Media Player to obtain the codec which we can't depend on. 

Meanwhile I'm getting bug reports from our test team that in some systems the video doesn't play at all even though I'm using Microsoft Video 1 which is their base codec installed on everything... 

Mar 6, 2012 at 11:46 PM

Okay while troubleshooting things I've found that I can't get ANY video playback from even the Sample Application on my XP SP3 virtual machine. The video runs fine in Windows Media Player 8, and the UI opens up, but opening a video file results in nothing showing up.

Mar 7, 2012 at 3:13 AM

You're probably talking about VC1 (which is the next-gen WMV comparable to MPEG-4 AVC and which is completely different from WMV9 and WMV8).

There are three common WMV formats: WMV8, WMV9 and VC1 (which I believe is also called WMV9 Advanced Profile).  You'll need the latest WMP to play VC1 I think.

However, maybe you can just install the K-Lite codec pack or something and then you'll be able to play everything.

Mar 9, 2012 at 8:04 PM

I'm still poking away at this rewind replay bug. I just noticed that when you set Loop to 'true' it does replay the video infinite times until told to stop. I'll be checking out that MediaPosition property and see what is going on...

May 2, 2012 at 10:06 PM

the video always plays with rate '1'. I can not set to different rate ;like '0.5','2','3'.Must be some bugs .

May 2, 2012 at 10:06 PM

the video always plays with rate '1'. I can not set to different rate ;like '0.5','2','3'.Must be some bugs .

May 18, 2012 at 6:13 AM
johnsonvictor wrote:

the video always plays with rate '1'. I can not set to different rate ;like '0.5','2','3'.Must be some bugs .

Same problem. I am running Windows 7. I found that Windows Media Player can play WMV with speedRaio from 0.5 to 2. But, in the sampleApp, when setting ratio to any value other than 1, I get error 80070057. Can anyone help? Thanks a lot!!!

May 18, 2012 at 1:31 PM

I found the problem .I just did the following

Comment the following line in  OpenSource() menthod from MediaUriPlayer.cs


It works for me.

Sep 28, 2012 at 11:44 AM

I also encountered the "third time the fail" bug when trying to set the MediaPosition back to 0. It only failed when the video played until completed before, however.

I could solve it by commenting out the StopGraphTimer() call in MediaPlayerBase.OnMediaEvent().

case EventCode.Complete:

This timer is only started when MediaOpened is raised and it's stopped when the media completes. So it never runs again after having completed once. The timer keeps running then, even though the video might be stopped, but I don't think this is much of a problem. It is stopped when Close()-ing the media.