IMFPMediaPlayer::CreateMediaItemFromURL method

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

Creates a media item from a URL.


HRESULT CreateMediaItemFromURL(
  [in]  LPCWSTR       pwszURL,
  [in]  BOOL          fSync,
  [in]  DWORD_PTR     dwUserData,
  [out] IMFPMediaItem **ppMediaItem


pwszURL [in]

Null-terminated string that contains the URL of a media file.

fSync [in]

If TRUE, the method blocks until it completes. If FALSE, the method does not block and completes asynchronously.

dwUserData [in]

Application-defined value to store in the media item. To retrieve this value from the media item, call IMFPMediaItem::GetUserData.

ppMediaItem [out]

Receives a pointer to the IMFPMediaItem interface. The caller must release the interface. If fSync is TRUE, this parameter must be a valid pointer. If bSync is FALSE, this parameter must be NULL.

Return value

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

Return codeDescription

The method succeeded.


Invalid argument.


Invalid request. This error can occur when fSync is FALSE and the application did not provide a callback interface. See Remarks.


The object's Shutdown method was called.


Unsupported protocol.



This method does not queue the media item for playback. To queue the item for playback, call IMFPMediaPlayer::SetMediaItem.

The CreateMediaItemFromURL method can be called either synchronously or asynchronously:

  • If fSync is TRUE, the method completes synchronously. The IMFPMediaItem pointer is returned in the ppMediaItem parameter.
  • If fSync is FALSE, the method completes asynchronously. When the operation completes, the application's IMFPMediaPlayerCallback::OnMediaPlayerEvent callback method is invoked. The event type is MFP_EVENT_TYPE_MEDIAITEM_CREATED. The event data contains the IMFPMediaItem pointer for the new media item.

The callback interface is set when you first call MFPCreateMediaPlayer to create the MFPlay player object. If you do not provide a callback interface, the fSync parameter must be TRUE. Otherwise, CreateMediaItemFromURL returns MF_E_INVALIDREQUEST.

If you make multiple asynchronous calls to CreateMediaItemFromURL, they are not guaranteed to complete in the same order. Use the dwUserData parameter to match created media items with pending requests.

Currently, this method returns MF_E_UNSUPPORTED_SCHEME if the URL specifies any of the following protocols: rtsp*, mms*, or mcast. If you want to use the Media Foundation network source with MFPlay, first use the Source Resolver to create the source, and then call IMFPMediaPlayer::CreateMediaItemFromObject.

Configuring the Source

Internally, this method creates a media source. To configure the media source, do the following:

  1. Call QueryInterface on the IMFPMediaPlayer pointer to get the IPropertyStore interface.
  2. Call IPropertyStore::SetValue to set properties for the media source. For a list of configuration properties, see Configuring a Media Source. Third-party media sources may define custom properties.
  3. Call the CreateMediaItemFromURL method to create the media item.


Minimum supported client

Windows 7 [desktop apps only]

Minimum supported server

Windows Server 2008 R2 [desktop apps only]



See also

Using MFPlay for Audio/Video Playback