Over a million developers have joined DZone.

Get the Total Duration of WMV Files Inside a Directory using C#



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.)

WMVDuration.exe C:\WMVDirectory\

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.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}