Signed-off-by: Nikolay Sivov <nsivov(a)codeweavers.com>
---
dlls/mfplay/player.c | 29 +++++++++++++++++++++++++++++
dlls/mfplay/tests/mfplay.c | 20 ++++++++++++++++++++
2 files changed, 49 insertions(+)
diff --git a/dlls/mfplay/player.c b/dlls/mfplay/player.c
index f6cb81de436..0bbe59f4c90 100644
--- a/dlls/mfplay/player.c
+++ b/dlls/mfplay/player.c
@@ -1911,14 +1911,26 @@ static const IMFAsyncCallbackVtbl media_player_session_events_callback_vtbl =
media_player_session_events_callback_Invoke,
};
+/***********************************************************************
+ * MFPCreateMediaPlayer (mfplay.@)
+ */
HRESULT WINAPI MFPCreateMediaPlayer(const WCHAR *url, BOOL start_playback, MFP_CREATION_OPTIONS options,
IMFPMediaPlayerCallback *callback, HWND window, IMFPMediaPlayer **player)
{
struct media_player *object;
+ IMFPMediaItem *item;
HRESULT hr;
TRACE("%s, %d, %#x, %p, %p, %p.\n", debugstr_w(url), start_playback, options, callback, window, player);
+ if (!player)
+ return E_POINTER;
+
+ *player = NULL;
+
+ if (!url && start_playback)
+ return E_INVALIDARG;
+
if (!(object = calloc(1, sizeof(*object))))
return E_OUTOFMEMORY;
@@ -1950,6 +1962,23 @@ HRESULT WINAPI MFPCreateMediaPlayer(const WCHAR *url, BOOL start_playback, MFP_C
0, mfplay_instance, NULL);
}
+ if (url)
+ {
+ if (FAILED(hr = media_player_create_item_from_url(object, url, TRUE, 0, &item)))
+ {
+ WARN("Failed to create media item, hr %#x.\n", hr);
+ goto failed;
+ }
+
+ hr = IMFPMediaPlayer_SetMediaItem(&object->IMFPMediaPlayer_iface, item);
+ IMFPMediaItem_Release(item);
+ if (FAILED(hr))
+ {
+ WARN("Failed to set media item, hr %#x.\n", hr);
+ goto failed;
+ }
+ }
+
*player = &object->IMFPMediaPlayer_iface;
return S_OK;
diff --git a/dlls/mfplay/tests/mfplay.c b/dlls/mfplay/tests/mfplay.c
index f11973ef939..a2d6da54f3e 100644
--- a/dlls/mfplay/tests/mfplay.c
+++ b/dlls/mfplay/tests/mfplay.c
@@ -87,6 +87,26 @@ static void test_create_player(void)
HWND window;
HRESULT hr;
+ hr = MFPCreateMediaPlayer(NULL, FALSE, 0, NULL, NULL, NULL);
+ ok(FAILED(hr), "Unexpected hr %#x.\n", hr);
+
+ hr = MFPCreateMediaPlayer(NULL, TRUE, 0, NULL, NULL, NULL);
+ ok(FAILED(hr), "Unexpected hr %#x.\n", hr);
+
+ player = (void *)0xdeadbeef;
+ hr = MFPCreateMediaPlayer(NULL, TRUE, 0, NULL, NULL, &player);
+ ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
+ ok(!player, "Unexpected pointer %p.\n", player);
+
+ hr = MFPCreateMediaPlayer(L"doesnotexist.mp4", FALSE, 0, &callback, NULL, NULL);
+ ok(hr == E_POINTER, "Unexpected hr %#x.\n", hr);
+
+ hr = MFPCreateMediaPlayer(L"doesnotexist.mp4", FALSE, 0, &callback, NULL, &player);
+ ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Unexpected hr %#x.\n", hr);
+
+ hr = MFPCreateMediaPlayer(NULL, TRUE, 0, &callback, NULL, &player);
+ ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
+
hr = MFPCreateMediaPlayer(NULL, FALSE, 0, NULL, NULL, &player);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
--
2.30.2