Alright. Actually i need mostly the mp4 format. But if it is possible to get for other types as well that would be nice. I just need to read the duration of the file. How can i do that with C# 4.0 ?
So the thing i need is like this video is like : 13 minutes 12 seconds
I can use 3 third party exes too. Like they save the information about the file to a text file. I can parse that text file.
Thank you.
You can use DirectShow API
MediaDet
object, through DirectShow.NET wrapper library. See Getting length of video for code sample,get_StreamLength
gets you the duration in seconds. This assumes Windows has MPEG-4 demultiplexer installed (requires third party components with Windows prior to 7, I believe the same applies to another answer by cezor, there are free to redistribute components though).This answer about P/Invoke for Shell32 reminded me of the Windows API Code Pack to access common Windows Vista/7/2008/2008R2 APIs.
It was very easy, using the PropertyEdit demo in the included samples, to figure out the Shell32 API to get various media file properties, like duration.
I assume the same prerequisite applies for having the proper demultiplexers installed, but it was quite simple, as it only required adding references to
Microsoft.WindowsAPICodePack.dll
andMicrosoft.WindowsAPICodePack.Shell.dll
and the following code:Other stuff
Some common properties for an MPEG-4/AAC audio media file:
It's easy to iterate through all properties if you're looking for the available metadata:
You could also use windows media player, although it don't support alle file types you requested