开发者

Determine length of audio file using DirectShow

I am just starting with DirectShow.NET, and I am trying to get the length (in seconds) of an audio file. The audio may be .mp3, .wav, .aac, or .m4a.

Can I get 开发者_StackOverflowthis information using DirectShow, or do I need some other APIs?


yes you can do this with DirectShow. There are a variety of ways to do this. One way is to query the IMediaSeeking interface on the graph object, and then call the GetDuration method on this interface.

GetDuration returns a 64bit integer value for how long it would take to play the file.

You will need to call the GetTimeFormat method to find out what units the duration is in. The most likely default value is TIME_FORMAT_MEDIA_TIME which is 10ths of a microsecond.

IN that case you would divide the duration by 10*1000*1000 to get seconds.

You can also call SetTimeFormat before calling GetDuration if you want to force the units.


You can also use get_Duration() from IMediaPosition interface.

This return a double value with the video duration in seconds.

    Double Lenght;

    m_FilterGraph = new FilterGraph()

//Configure the FilterGraph()

    m_mediaPosition = m_FilterGraph as IMediaPosition;
    m_mediaPosition.get_Duration(out Length);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜