Get SystemMediaTransportControls for other window
Asked Answered
P

1

1

I'm interesting in ISystemMediaTransportControlsInterop::GetForWindow method. The documentation is outdated for it. But I have found files SystemMediaTransportControlsInterop.h and SystemMediaTransportControlsInterop.idl in folder C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um of Windows SDK. They are describing GetForWindow method. So, how can I get an instance of ISystemMediaTransportControlsInterop and call this method?

WinRT contains only method SystemMediaTransportControls.GetForCurrentView, but I want to get an instance of SystemMediaTransportControls for other program from my application.

Thank you

Pronghorn answered 5/6, 2020 at 19:27 Comment(2)
The documentation isn't outdated. The content isn't being updated regularly. That does not imply that the documentation were inaccurate. I'm not sure what the issue is now.Chara
Only the process that owns the window can get/create its SMTC. It is not intended for you to manipulate the SMTC that belongs to other windows. This is implied by GetForCurrentView, since the current view is defined as the view associated with the current thread, which is naturally also part of the calling process.Spenserian
P
0

So, I have found, that WinRT is based on COM technology. And we can get ActivationFactory to call method from interop interface. For example, on C#:

[Guid("ddb0472d-c911-4a1f-86d9-dc3d71a95f5a")]
[InterfaceType(ComInterfaceType.InterfaceIsIInspectable)]
public interface ISystemMediaTransportControlsInterop
{
    SystemMediaTransportControls GetForWindow(IntPtr Window, [In] ref Guid riid);
}

var smtcInterop = (ISystemMediaTransportControlsInterop)WindowsRuntimeMarshal.GetActivationFactory(typeof(SystemMediaTransportControls));
var guid = typeof(SystemMediaTransportControls).GUID;
var smtc = smtcInterop.GetForWindow(hwnd, ref guid);

But the problem is, that I receive access denied exception if I try SMTC instance of other window.

Pronghorn answered 10/6, 2020 at 18:4 Comment(4)
I'm looking for a solution to use this API at all. Could you help me with some more details about your code sample? Where can I find the missing types?Pangolin
What exactly types do you need?Pronghorn
My scenario is to control my media player (custom app, Windows Forms) from the Bluetooth headset controls (works with Firefox/YouTube, play/pause, prev/next, volume up/down).Pangolin
@Pangolin I think GlobalSystemMediaTransportControlsSessionManager is what you need. It allows control global media.Pronghorn

© 2022 - 2024 — McMap. All rights reserved.