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
- Call IMFPMediaPlayer::CreateMediaItemFromURL or IMFPMediaPlayer::CreateMediaItemFromObject to create a media item for the file.
- 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.
Related topics
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for