Get the Total Duration of WMV Files Inside a Directory using C#
Join the DZone community and get the full member experience.Join For Free
since becoming a pluralsight author, i’ve often needed to get the total duration of all the .wmv files inside of a directory. i would typically use an application that they provide, but it requires you to load each module one by one. i decided i’d write a quick and dirty application that would return the total duration using the windowsmediaplayer class.
how to use it
simply download the code off of github and add a reference to the file located at : “c:\program files (x86)\microsoft visual studio 11.0\common7\ide\privateassemblies\wmplib.dll” (using vs2013 – if you are using another version of visual studio then just search your system for the file called, “wmplib.dll”). build the project or grab the executable here and run the following command inside the folder that wmvduration.exe exist. (fyi: i built this with the .net 4.5 framework, which is overkill, but was the default.)
below is an example of it running on my current course.
disclaimer : keep in mind that this code has not been tested but works for my situation. it would be easy to modify this to support mp4 files for mac, rounding the milliseconds up, etc.
thanks again for reading and i hope you have a wonderful day!
Published at DZone with permission of Michael Crump. See the original article here.
Opinions expressed by DZone contributors are their own.