From: Mohamad Al-Jaf mohamadaljaf@gmail.com
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=58631 --- .../Makefile.in | 2 +- .../windows.media.playback.mediaplayer/main.c | 49 +++++++++++++++++-- .../private.h | 2 + .../tests/mediaplayer.c | 13 +++++ 4 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/dlls/windows.media.playback.mediaplayer/Makefile.in b/dlls/windows.media.playback.mediaplayer/Makefile.in index 9fa6895c9ea..f37a609b848 100644 --- a/dlls/windows.media.playback.mediaplayer/Makefile.in +++ b/dlls/windows.media.playback.mediaplayer/Makefile.in @@ -1,5 +1,5 @@ MODULE = windows.media.playback.mediaplayer.dll -IMPORTS = combase +IMPORTS = combase user32
SOURCES = \ classes.idl \ diff --git a/dlls/windows.media.playback.mediaplayer/main.c b/dlls/windows.media.playback.mediaplayer/main.c index 67b50ba065b..d7780c17028 100644 --- a/dlls/windows.media.playback.mediaplayer/main.c +++ b/dlls/windows.media.playback.mediaplayer/main.c @@ -29,6 +29,9 @@ struct media_player IMediaPlayer IMediaPlayer_iface; IMediaPlayer2 IMediaPlayer2_iface; LONG ref; + + ISystemMediaTransportControls *controls; + HWND window; };
static inline struct media_player *impl_from_IMediaPlayer( IMediaPlayer *iface ) @@ -79,7 +82,12 @@ static ULONG WINAPI media_player_Release( IMediaPlayer *iface )
TRACE( "iface %p decreasing refcount to %lu.\n", iface, ref );
- if (!ref) free( impl ); + if (!ref) + { + ISystemMediaTransportControls_Release( impl->controls ); + DestroyWindow( impl->window ); + free( impl ); + } return ref; }
@@ -414,10 +422,45 @@ static const struct IMediaPlayerVtbl media_player_vtbl =
DEFINE_IINSPECTABLE( media_player2, IMediaPlayer2, struct media_player, IMediaPlayer_iface )
+static HRESULT get_system_media_transport_controls( HWND *window, ISystemMediaTransportControls **controls ) +{ + static const WCHAR *media_control_statics_name = L"Windows.Media.SystemMediaTransportControls"; + ISystemMediaTransportControlsInterop *media_control_interop_statics = NULL; + IActivationFactory *factory = NULL; + HSTRING str = NULL; + HRESULT hr; + + if (!(*window = GetActiveWindow())) + if (!(*window = CreateWindowExA( 0, "static", 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, GetModuleHandleA( NULL ), 0 ))) + return HRESULT_FROM_WIN32( GetLastError() ); + + hr = WindowsCreateString( media_control_statics_name, wcslen( media_control_statics_name ), &str ); + if (SUCCEEDED(hr)) hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory ); + if (SUCCEEDED(hr)) hr = IActivationFactory_QueryInterface( factory, &IID_ISystemMediaTransportControlsInterop, (void **)&media_control_interop_statics ); + if (SUCCEEDED(hr)) hr = ISystemMediaTransportControlsInterop_GetForWindow( media_control_interop_statics, *window, &IID_ISystemMediaTransportControls, (void **)controls ); + + if (media_control_interop_statics) ISystemMediaTransportControlsInterop_Release( media_control_interop_statics ); + if (factory) IActivationFactory_Release( factory ); + WindowsDeleteString( str ); + return hr; +} + static HRESULT WINAPI media_player2_get_SystemMediaTransportControls( IMediaPlayer2 *iface, ISystemMediaTransportControls **value ) { - FIXME( "iface %p, value %p stub!\n", iface, value ); - return E_NOTIMPL; + struct media_player *impl = impl_from_IMediaPlayer2( iface ); + HRESULT hr; + + TRACE( "iface %p, value %p\n", iface, value ); + + if (!impl->controls && FAILED(hr = get_system_media_transport_controls( &impl->window, &impl->controls ))) + { + *value = NULL; + return hr; + } + + *value = impl->controls; + ISystemMediaTransportControls_AddRef( *value ); + return S_OK; }
static HRESULT WINAPI media_player2_get_AudioCategory( IMediaPlayer2 *iface, MediaPlayerAudioCategory *value ) diff --git a/dlls/windows.media.playback.mediaplayer/private.h b/dlls/windows.media.playback.mediaplayer/private.h index d5bbba3206a..f1bc402a3b2 100644 --- a/dlls/windows.media.playback.mediaplayer/private.h +++ b/dlls/windows.media.playback.mediaplayer/private.h @@ -28,6 +28,7 @@ #include "winstring.h"
#include "activation.h" +#include "roapi.h"
#define WIDL_using_Windows_Foundation #define WIDL_using_Windows_Foundation_Collections @@ -35,6 +36,7 @@ #define WIDL_using_Windows_Media #define WIDL_using_Windows_Media_Playback #include "windows.media.playback.h" +#include "systemmediatransportcontrolsinterop.h"
#define DEFINE_IINSPECTABLE_( pfx, iface_type, impl_type, impl_from, iface_mem, expr ) \ static inline impl_type *impl_from( iface_type *iface ) \ diff --git a/dlls/windows.media.playback.mediaplayer/tests/mediaplayer.c b/dlls/windows.media.playback.mediaplayer/tests/mediaplayer.c index 93b0a3d71a4..142c86ed191 100644 --- a/dlls/windows.media.playback.mediaplayer/tests/mediaplayer.c +++ b/dlls/windows.media.playback.mediaplayer/tests/mediaplayer.c @@ -28,6 +28,7 @@ #define WIDL_using_Windows_Foundation #define WIDL_using_Windows_Foundation_Collections #include "windows.foundation.h" +#define WIDL_using_Windows_Media #define WIDL_using_Windows_Media_Playback #include "windows.media.playback.h"
@@ -48,6 +49,8 @@ static void check_interface_( unsigned int line, void *obj, const IID *iid, BOOL static void test_MediaPlayer_Statics(void) { static const WCHAR *media_player_name = L"Windows.Media.Playback.MediaPlayer"; + ISystemMediaTransportControls *media_transport_controls2 = NULL; + ISystemMediaTransportControls *media_transport_controls = NULL; IMediaPlayer2 *media_player2 = (void *)0xdeadbeef; IActivationFactory *factory = (void *)0xdeadbeef; IMediaPlayer *media_player = (void *)0xdeadbeef; @@ -85,6 +88,16 @@ static void test_MediaPlayer_Statics(void) hr = IMediaPlayer_QueryInterface( media_player, &IID_IMediaPlayer2, (void **)&media_player2 ); ok( hr == S_OK, "got hr %#lx.\n", hr );
+ hr = IMediaPlayer2_get_SystemMediaTransportControls( media_player2, &media_transport_controls ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = IMediaPlayer2_get_SystemMediaTransportControls( media_player2, &media_transport_controls2 ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + ok( media_transport_controls == media_transport_controls2, "got media_transport_controls %p, media_transport_controls2 %p.\n", media_transport_controls, media_transport_controls2 ); + ref = ISystemMediaTransportControls_Release( media_transport_controls2 ); + ok( ref == 3, "got ref %ld.\n", ref ); + + ref = ISystemMediaTransportControls_Release( media_transport_controls ); + ok( ref == 2, "got ref %ld.\n", ref ); ref = IMediaPlayer2_Release( media_player2 ); ok( ref == 2, "got ref %ld.\n", ref ); ref = IMediaPlayer_Release( media_player );