Compartir a través de


MFPCreateMediaPlayer function (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 new instance of the MFPlay player object.

Syntax

HRESULT MFPCreateMediaPlayer(
  [in]  LPCWSTR                 pwszURL,
  [in]  BOOL                    fStartPlayback,
  [in]  MFP_CREATION_OPTIONS    creationOptions,
  [in]  IMFPMediaPlayerCallback *pCallback,
  [in]  HWND                    hWnd,
  [out] IMFPMediaPlayer         **ppMediaPlayer
);

Parameters

[in] pwszURL

Null-terminated string that contains the URL of a media file to open. This parameter can be NULL. If the parameter is NULL, fStartPlayback must be FALSE.

If this parameter is NULL, you can open a URL later by calling IMFPMediaPlayer::CreateMediaItemFromURL.

[in] fStartPlayback

If TRUE, playback starts automatically. If FALSE, playback does not start until the application calls IMFMediaPlayer::Play.

If pwszURL is NULL, this parameter is ignored.

[in] creationOptions

Bitwise OR of zero of more flags from the _MFP_CREATION_OPTIONS enumeration.

[in] pCallback

Pointer to the IMFPMediaPlayerCallback interface of a callback object, implemented by the application. Use this interface to get event notifications from the MFPlay player object. This parameter can be NULL. If the parameter is NULL, the application will not receive event notifications from the player object.

[in] hWnd

A handle to a window where the video will appear. For audio-only playback, this parameter can be NULL.

The window specified by hWnd is used for the first selected video stream in the source. If the source has multiple video streams, you must call IMFPMediaItem::SetStreamSink to render any of the video streams after the first.

If hWnd is NULL, MFPlay will not display any video unless the application calls IMFPMediaItem::SetStreamSink to specify a media sink for the video stream.

[out] ppMediaPlayer

Receives a pointer to the IMFPMediaPlayer interface. The caller must release the interface. This parameter can be NULL. If this parameter is NULL, fStartPlayback must be TRUE and pwszURL cannot be NULL.

Return value

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

Remarks

Before calling this function, call CoIntialize(Ex) from the same thread to initialize the COM library.

Internally, MFPCreateMediaPlayer calls MFStartup to initialize the Microsoft Media Foundation platform. When the player object is destroyed, it calls MFShutdown to shut down the platform. It is not necessary for an application to call MFStartup or MFShutdown when using MFPlay.

Note  If you use other Media Foundation APIs outside the life time of the player object, then your application should call MFStartup and MFShutdown.
 

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
Library Mfplay.lib
DLL Mfplay.dll

See also

Media Foundation Functions

Using MFPlay for Audio/Video Playback