IMFPMediaItem::SetStartStopPosition method (mfplay.h)

Important  Deprecated. This API may be removed from future releases of Windows. Applications should use the Media Session for playback.

Sets the start and stop time for the media item.


HRESULT SetStartStopPosition(
  [in] const GUID        *pguidStartPositionType,
  [in] const PROPVARIANT *pvStartValue,
  [in] const GUID        *pguidStopPositionType,
  [in] const PROPVARIANT *pvStopValue


[in] pguidStartPositionType

Unit of time for the start position. See Remarks. This parameter can be NULL.

[in] pvStartValue

Start position. The meaning and data type of this parameter are indicated by the pguidStartPositionType parameter. The pvStartValue parameter must be NULL if pguidStartPositionType is NULL, and cannot be NULL otherwise.

[in] pguidStopPositionType

Unit of time for the stop position. See Remarks. This parameter can be NULL.

[in] pvStopValue

Stop position. The meaning and data type of this parameter are indicated by the pguidStopPositionType parameter. The pvStopValue parameter must be NULL if pguidStopPositionType is NULL, and cannot be NULL otherwise.

Return value

The method returns an HRESULT. Possible values include, but are not limited to, those in the following table.

Return code Description
The method succeeded.
Invalid argument.
Invalid start or stop time. Any of the following can cause this error:
  • Time less than zero.
  • Time greater than the total duration of the media item.
  • Stop time less than start time.


By default, a media item plays from the beginning to the end of the file. This method adjusts the start time and/or the stop time:

  • To set the start time, pass non-NULL values for pguidStartPositionType and pvStartValue.
  • To set the stop time, pass non-NULL values for pguidStopPositionType and pvStopValue.
The pguidStartPositionType and pguidStopPositionType parameters give the units of time that are used. Currently, the only supported value is MFP_POSITIONTYPE_100NS.
Value Description
MFP_POSITIONTYPE_100NS 100-nanosecond units. The time parameter (pvStartValue or pvStopValue) uses the following data type:
  • Variant type (vt): VT_I8
  • Variant member: hVal
To clear a previously set time, use an empty PROPVARIANT (VT_EMPTY).

The adjusted start and stop times are used the next time that IMFPMediaPlayer::SetMediaItem is called with this media item. If the media item is already set on the player, the change does not happen unless you call SetMediaItem again.


HRESULT PlayMediaClip(
    IMFPMediaPlayer *pPlayer,
    PCWSTR pszURL,
    LONGLONG    hnsStart,
    LONGLONG    hnsEnd
    IMFPMediaItem *pItem = NULL;
    PROPVARIANT varStart, varEnd;

    ULONGLONG hnsDuration = 0;

    HRESULT hr = pPlayer->CreateMediaItemFromURL(pszURL, TRUE, 0, &pItem);
    if (FAILED(hr))
        goto done;

    hr = GetPlaybackDuration(pItem, &hnsDuration);
    if (FAILED(hr))
        goto done;

    if ((ULONGLONG)hnsEnd > hnsDuration)
        hnsEnd = hnsDuration;

    hr = InitPropVariantFromInt64(hnsStart, &varStart);
    if (FAILED(hr))
        goto done;

    hr = InitPropVariantFromInt64(hnsEnd, &varEnd);
    if (FAILED(hr))
        goto done;

    hr = pItem->SetStartStopPosition(
    if (FAILED(hr))
        goto done;

    hr = pPlayer->SetMediaItem(pItem);

    return hr;


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 Play a File Clip


Using MFPlay for Audio/Video Playback