how to get a AVI file''s width and height?
hello,everyone:
before I play a avi file, I want to get the width and height of this avi media,
then I set the main window width and height to fit it.
at last, I play it.
how can I do it?
I once tried the control MediaElement,but before it play, I get the width the height as zero.
please give some suggestions?
thanks!
yeah, you are right.
but I mean before it play, I must get the width and height because I must set the main window's width and height,
and then I play the avi file.
I try it as follows:
void WinLoaded(object sender, RoutedEventArgs e)
{
MediaPlayer MP = new MediaPlayer();
MP.Open(new Uri(@"D:\Accept.avi"));
int wid = MP.NaturalVideoWidth;
int hg = MP.NaturalVideoHeight;
}
MP.NaturalVideoWidth and MP.NaturalVideoHeight is right,
but the wid variable and hg variable is 0.
why?
I think Yiling was suggesting checking the natrualvideowidth/height after the MediaOpened event is called. The properties might not be populated right after you set the source because the media is loaded async.
If that does not work, try this: http://www.codeproject.com/cs/media/aviFileWrapper.asp
You'd be interested in the AVIFILEINFO struct and AviFileInfo() method.
-Jer
Hello, Both ActualWidth and NaturalVideoWidth is not accurate until the MediaOpened event has been raised. I think if you need to get video with before the file is opened by MediaElement, you should do parse yourself. Anyway, we should parse the file, either the work is done by MediaElement or by yourself, Are you agree it?