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!

[781 byte] By [bruce.du] at [2008-1-9]
# 1

For video content, once the MediaElement.MediaOpened event has been raised the ActualWidth and ActualHeight will report the size of the loaded media.

YilingLai at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2

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?

bruce.du at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3

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

JeremiahMorrill at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 4

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?

YilingLai at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified