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 | 64 +++++++++++++++++-- .../private.h | 2 + .../tests/mediaplayer.c | 13 ++++ 4 files changed, 74 insertions(+), 7 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..191771038ca 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,15 @@ static ULONG WINAPI media_player_Release( IMediaPlayer *iface )
TRACE( "iface %p decreasing refcount to %lu.\n", iface, ref );
- if (!ref) free( impl ); + if (!ref) + { + if (impl->controls) + { + ISystemMediaTransportControls_Release( impl->controls ); + DestroyWindow( impl->window ); + } + free( impl ); + } return ref; }
@@ -416,8 +427,13 @@ DEFINE_IINSPECTABLE( media_player2, IMediaPlayer2, struct media_player, IMediaPl
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 ); + + TRACE( "iface %p, value %p\n", iface, value ); + + *value = impl->controls; + ISystemMediaTransportControls_AddRef( *value ); + return S_OK; }
static HRESULT WINAPI media_player2_get_AudioCategory( IMediaPlayer2 *iface, MediaPlayerAudioCategory *value ) @@ -527,16 +543,52 @@ static HRESULT WINAPI factory_GetTrustLevel( IActivationFactory *iface, TrustLev return E_NOTIMPL; }
+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; + HWND hwnd; + + FIXME( "shell integration not implemented.\n" ); + + if (!(hwnd = CreateWindowExW( 0, L"static", NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandleW( NULL ), NULL ))) return HRESULT_FROM_WIN32( GetLastError() ); + + if (FAILED(hr = WindowsCreateString( media_control_statics_name, wcslen( media_control_statics_name ), &str ))) goto done; + if (SUCCEEDED(hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory ))) + { + hr = IActivationFactory_QueryInterface( factory, &IID_ISystemMediaTransportControlsInterop, (void **)&media_control_interop_statics ); + IActivationFactory_Release( factory ); + } + if (SUCCEEDED(hr)) + { + hr = ISystemMediaTransportControlsInterop_GetForWindow( media_control_interop_statics, hwnd, &IID_ISystemMediaTransportControls, (void **)controls ); + ISystemMediaTransportControlsInterop_Release( media_control_interop_statics ); + } + WindowsDeleteString( str ); + +done: + if (FAILED(hr)) DestroyWindow( hwnd ); + else *window = hwnd; + return hr; +} + static HRESULT WINAPI factory_ActivateInstance( IActivationFactory *iface, IInspectable **instance ) { struct media_player *impl; + HRESULT hr;
TRACE( "iface %p, instance %p.\n", iface, instance );
- if (!(impl = calloc( 1, sizeof( *impl ) ))) + *instance = NULL; + + if (!(impl = calloc( 1, sizeof( *impl ) ))) return E_OUTOFMEMORY; + if (FAILED(hr = get_system_media_transport_controls( &impl->window, &impl->controls ))) { - *instance = NULL; - return E_OUTOFMEMORY; + free( impl ); + return hr; }
impl->IMediaPlayer_iface.lpVtbl = &media_player_vtbl; 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..8b3af42ae8d 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 = (void *)0xdeadbeef; + ISystemMediaTransportControls *media_transport_controls = (void *)0xdeadbeef; 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 );