How to Get the Playback Duration

[MFPlay is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions. ]

This topic describes how to get the playback duration of a media file using MFPlay.

To Get the Playback Duration

  1. Call IMFPMediaPlayer::CreateMediaItemFromURL or IMFPMediaPlayer::CreateMediaItemFromObject to create a media item for the file.
  2. Call IMFPMediaItem::GetDuration. Specify MFP_POSITIONTYPE_100NS for the first parameter. The duration is returned as a PROPVARIANT that contains a LARGE_INTEGER value. The duration is given in 100-nanosecond units.

The following example shows step 2:

#include <propvarutil.h>

HRESULT GetPlaybackDuration(IMFPMediaItem *pItem, ULONGLONG *phnsDuration)
{
    PROPVARIANT var;

    HRESULT hr = pItem->GetDuration(MFP_POSITIONTYPE_100NS, &var);

    if (SUCCEEDED(hr))
    {
        hr = PropVariantToUInt64(var, phnsDuration);
        PropVariantClear(&var);
    }

    return hr;
}

Requirements

MFPlay requires Windows 7.

Using MFPlay for Audio/Video Playback