Solved

C# retrieve the duration of media files such as .avi, wmv, wma, wav, etc

Posted on 2009-05-08
1
1,364 Views
Last Modified: 2012-05-06
Is there a way of retrieving the duration of media files (avi, wmv, wma, wav, etc) from a command line application? At the moment I can use an instance of AxWindowsMediaPlayer, but this only seems to work for audio .wma.
AxWMPLib.AxWindowsMediaPlayer objPlayer = new AxWMPLib.AxWindowsMediaPlayer();
               WMPLib.IWMPMedia media = objPlayer.newMedia(strMediaFilePath);
                dblDuration = media.duration;

Open in new window

0
Comment
Question by:ttnetworks
1 Comment
 
LVL 12

Accepted Solution

by:
williamcampbell earned 250 total points
ID: 24337889

With DirectShow, you can use IGraphBuilder::RenderFile() to create a graph
and then use IMediaSeeking::GetDuration().

Otherwise, you can use the IMediaDet interface (which does the above
internally).

So you could create a C++ DLL and then use p/Invoke too grab the result form C# land.

Google the above and you may find some code.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB: Convert 2 dates to specific format 24 52
Where is this file? 3 25
ASP.NET MVC -Update model when click on <li> element 29 34
Why use this lambda? 12 37
I have a Synology DS212+ NAS.  These are not only great for backup and normal NAS stuff, but also for delivering media throughout your home or LAN via DLNA.  I copied my whole audio collection from iTunes over to the box, but couldn't figure out how…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video teaches viewers how to process images for a time-lapse video. Programs required: Adobe Lightroom, Adobe After Effects, Video Editing Program. In Adobe Lightroom: Import sequence image files into Adobe Lightroom: Develop settings of an I…
Viewers will learn how to include realistic velocity sensitivity to their Sampler instruments. Set the Vol<Vel parameter in the Filter/Global tab to your desired setting: Gather samples of hits of various intensity, and drag/drop into Velocity zon…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question