【问题标题】:Get SystemMediaTransportControls for other window获取其他窗口的 SystemMediaTransportControls
【发布时间】:2023-03-25 14:40:01
【问题描述】:

我对@9​​87654321@ 方法很感兴趣。该文档已过时。但我在文件夹 C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0 中找到了文件 SystemMediaTransportControlsInterop.hSystemMediaTransportControlsInterop.idl \um 的 Windows SDK。他们正在描述GetForWindow 方法。那么,如何获取ISystemMediaTransportControlsInterop 的实例并调用该方法呢?

WinRT 仅包含方法 SystemMediaTransportControls.GetForCurrentView,但我想从我的应用程序中为其他程序获取 SystemMediaTransportControls 的实例。

谢谢

【问题讨论】:

  • 文档没有过时。内容不定期更新。这并不意味着文档不准确。我不确定现在是什么问题。
  • 只有拥有窗口的进程才能获取/创建它的 SMTC。它不打算让您操作属于其他窗口的 SMTC。 GetForCurrentView 暗示了这一点,因为当前视图被定义为与当前线程关联的视图,这自然也是调用进程的一部分。

标签: uwp com windows-10 windows-runtime c++-winrt


【解决方案1】:

所以,我发现 WinRT 是基于 COM 技术的。我们可以得到ActivationFactory 从互操作接口调用方法。 例如,在 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);

但问题是,如果我尝试其他窗口的 SMTC 实例,我会收到拒绝访问异常。

【讨论】:

  • 我正在寻找一种完全使用此 API 的解决方案。您能帮我提供有关您的代码示例的更多详细信息吗?在哪里可以找到缺失的类型?
  • 你到底需要什么类型?
  • 我的场景是通过蓝牙耳机控件(适用于 Firefox/YouTube、播放/暂停、上一个/下一个、音量增大/减小)控制我的媒体播放器(自定义应用程序、Windows 窗体)。
  • @ygoe 我认为GlobalSystemMediaTransportControlsSessionManager 是您所需要的。它允许控制全球媒体。
猜你喜欢
  • 2013-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-09
  • 1970-01-01
  • 1970-01-01
  • 2014-08-07
  • 1970-01-01
相关资源
最近更新 更多