Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting duration for audio or video clip without actually playing the clip

713 views
Skip to first unread message

Warrick Wilson

unread,
Dec 16, 2003, 6:28:53 PM12/16/03
to
Is there ANY way to get data about a clip - wmv, avi, mp3, mp2 ... whatever,
as long as there's a codec for it - without actually PLAYING the file? I'm
using Windows XP Pro and WMP9 SDK for development, and I'm actually using
Delphi, but I can probably figure out the appropriate syntax once I know the
actual incantation to use in some other language.

I'm open to using DirectX calls to do it, if required. Would beat what I'm
doing now...

Thanks...Warrick


Alessandro Angeli [MVP::DigitalMedia]

unread,
Dec 17, 2003, 4:25:56 AM12/17/03
to
Since WMP uses DirectShow (part of DirectX), that's the best way to do it.

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

http://msdn.microsoft.com/library/en-us/directx9_c/directX/htm/howtoplayafile.asp

on how to render a file (you don't need to actually play it, that is call
IMediaControl::Run()).

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

"Warrick Wilson" <warr...@mercuryonline.com> wrote:

--

Alessandro Angeli

MVP::DigitalMedia

a dot angeli at biosys dot net

bryanw

unread,
Dec 17, 2003, 4:39:30 PM12/17/03
to
"Warrick Wilson" <warr...@mercuryonline.com> wrote in message news:<ON3BUyCx...@TK2MSFTNGP11.phx.gbl>...

> Is there ANY way to get data about a clip - wmv, avi, mp3, mp2 ... whatever,
> as long as there's a codec for it - without actually PLAYING the file?

Look in the Windows Media <b>Format</b> SDK. I do this in managed C#
so it's probably a bit different and MSFT provides a C# wrapper class
to the COM IWMHeaderInfo3 class which has functions like
GetAttributeCount and GetAttributeByName plus a bunch of others.

bryanw

unread,
Dec 18, 2003, 10:45:41 AM12/18/03
to
bryanwi...@yahoo.com (bryanw) wrote in message news:<30b55a51.03121...@posting.google.com>...

After looking at it last night I realized I was mistaken; the APIs to
do this are in the Player SDK and not the Format SDK. Sorry about
that.

Player.newMedia() is the key interface for this purpose. Here is a
code sample:

-----------------------------------------------

Microsoft.MediaPlayer.Interop.IWMPMedia m = Player.newMedia(fileName);

string currentArtist = m.getItemInfo("Author").Trim();
string currentAlbum = m.getItemInfo("Album").Trim();
string currentTitle = m.getItemInfo("Title").Trim();
double duration = m.duration;

Console.WriteLine(fileName);
Console.WriteLine("\tArtist : {0}", currentArtist);
Console.WriteLine("\tAlbum : {0}", currentAlbum);
Console.WriteLine("\tTitle : {0}", currentTitle);
Console.WriteLine("\tDuration: {0}", duration);


m.setItemInfo("Author", "bla");
m.setItemInfo("Album", "de");
m.setItemInfo("Title", "bla");

0 new messages