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

Introduction

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.

image

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. 

Wrap-Up

Thanks again for reading and I hope you have a wonderful day!



csharp
Posted by: Michael Crump
Last revised: 23 Jan, 2014 01:22 AM

Comments

No comments yet. Be the first!

No new comments are allowed on this post.

Hosting provided by http://www.DiscountASP.NET