IMFPMediaPlayer::CreateMediaItemFromObject 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.]
Creates a media item from an object.
Syntax
HRESULT CreateMediaItemFromObject(
[in] IUnknown *pIUnknownObj,
[in] BOOL fSync,
[in] DWORD_PTR dwUserData,
[out] IMFPMediaItem **ppMediaItem
);
Parameters
[in] pIUnknownObj
A pointer to the object's IUnknown interface. See Remarks.
[in] fSync
If TRUE, the method blocks until it completes. If FALSE, the method does not block and completes asynchronously.
[in] dwUserData
Application-defined value to store in the media item. To retrieve this value from the media item, call IMFPMediaItem::GetUserData.
[out] ppMediaItem
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 code | Description |
---|---|
|
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. |
Remarks
The pIUnknownObj parameter must specify one of the following:
- A pointer to a media source. Media sources expose the IMFMediaSource interface. It is the caller's responsibility to call IMFMediaSource::Shutdown on the media source.
- A pointer to a byte stream. Byte streams expose the IMFByteStream interface. Internally, the method calls the IMFSourceResolver::CreateObjectFromByteStream method to create a media source from the byte stream. Therefore, a byte-stream handler must be registered for the byte stream. For more information about byte-stream handlers, see Scheme Handlers and Byte-Stream Handlers.
The CreateMediaItemFromObject 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.
If you make multiple asynchronous calls to CreateMediaItemFromObject, they are not guaranteed to complete in the same order. Use the dwUserData parameter to match created media items with pending requests.
Configuring the Source
If pIUnknownObj points to a byte stream, you can configure the media source by performing the following steps:- Call QueryInterface on the IMFPMediaPlayer pointer to get the IPropertyStore interface.
- 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.
- Call the CreateMediaItemFromObject method to create the media item.
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 |