mfplay: Create media item on player creation, when url is specified.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2021-06-18 19:28:53 +03:00 committed by Alexandre Julliard
parent 617d14bc12
commit 352da005c1
2 changed files with 49 additions and 0 deletions

View File

@ -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;

View File

@ -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);