共用方式為


IMFPMediaItem::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 duration of the media item.

Syntax

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

Parameters

[in] guidPositionType

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

Value Meaning
MFP_POSITIONTYPE_100NS
100-nanosecond units.

The value returned in pvDurationValue is a LARGE_INTEGER.

  • Variant type (vt): VT_I8
  • Variant member: hVal

[out] pvDurationValue

Pointer to a PROPVARIANT that receives the duration.

Return value

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

The method returns the total duration of the content, regardless of any values set through IMFPMediaItem::SetStartStopPosition.

Examples

#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

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

How to Get the Playback Duration

IMFPMediaItem

Using MFPlay for Audio/Video Playback