Share via


IMFPMediaPlayer::GetDuration method (mfplay.h)

[The feature associated with this page, MFPlay, is a legacy feature. It has been superseded by MediaPlayer and IMFMediaEngine. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer and IMFMediaEngine instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

Gets the playback duration of the current media item.

Syntax

HRESULT GetDuration(
  [in]  REFGUID     guidPositionType,
  [out] PROPVARIANT *pvDurationValue
);

Parameters

[in] guidPositionType

Specifies the unit of time for the duration. The following value is defined.

Value Meaning
MFP_POSITIONTYPE_100NS
100-nanosecond units.

The value returned in pvDurationValue is a ULARGE_INTEGER.

  • Variant type (vt): VT_UI8
  • Variant member: uhVal

[out] pvDurationValue

Pointer to a PROPVARIANT that receives the duration.

Return value

This method can return one of these values.

Return code Description
S_OK
The method succeeded.
MF_E_ATTRIBUTENOTFOUND
The media source does not have a duration. This error can occur with a live source, such as a video camera.
MF_E_INVALIDREQUEST
There is no current media item.

Remarks

This method calculates the playback duration, taking into account the start and stop times for the media item. To set the start and stop times, call IMFPMediaItem::SetStartStopPosition on the media item. To get the actual duration of the underlying media file, regardless of start and stop times, call IMFPMediaItem::GetDuration.

For example, suppose that you load a 30-second audio file and set the start time equal to 2 seconds and stop time equal to 10 seconds. The IMFPMediaItem::GetDuration method will return 30 seconds, but the IMFPMediaPlayer::GetDuration method will return 8 seconds.

Requirements

Requirement Value
Minimum supported client Windows 7 [desktop apps only]
Minimum supported server Windows Server 2008 R2 [desktop apps only]
Target Platform Windows
Header mfplay.h

See also

IMFPMediaPlayer

Using MFPlay for Audio/Video Playback