从 Microsoft Groove Music 应用获取当前播放曲目信息 [英] Get current playing track info from Microsoft Groove Music app

查看:24
本文介绍了从 Microsoft Groove Music 应用获取当前播放曲目信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我自己的应用中获取 Microsoft Groove 应用中当前播放曲目的曲目信息.我说的是 Groove APP 而不是 REST Api.

我的第一种方法是尝试从我自己的进程(应用程序)中获取 Windows.Media.Playback.BackgroundMediaPlayer(现已过时)信息.

上面链接的关于 SMTC 的文章展示了如何在您的应用程序中使用这些控件,我想做的事情基本上完全相反.

是否有人有其他您认为可行的方法?

编辑

所以我发现使用原生的 ISystemMediaTransportControlsInterop 接口可能是可能的:

https://msdn.microsoft.com/en-us/library/windows/desktop/dn892315(v=vs.85).aspx

更准确的 ISystemMediaTransportControlsInterop::GetForWindow 方法:

https://msdn.microsoft.com/en-us/library/windows/desktop/dn892316(v=vs.85).aspx

但我不知道如何调用这个方法,使用什么库(dll)所以我可以(也许)在我的 C# 应用程序中调用它.

文档说这包含在 Windows 10 SDK 中,但我不知道在哪里.

也许我完全错了,也许我不能在 C# 中使用它(因为它是一个 C++ 接口).但我的想法是,必须将其编译到一个库中,并且我可以通过使用 pInvoke 来使用它.

如果有人能向我解释这一点,我们将不胜感激.

解决方案

https://docs.microsoft.com/en-us/uwp/api/Windows.Media.SystemMediaTransportControls

SystemMediaTransportControls _control = SystemMediaTransportControls.GetForCurrentView();

Windows.Foundation.UniversalApiContract.winmd 是您访问 SMTC 类所需的合同.

参考此内容,您应该能够获得控制权.

<HintPath>C:Program Files (x86)Windows Kits10ReferencesWindows.Foundation.UniversalApiContract3‌ .0.0.0Windows.Found‌ ation.UniversalApiCo‌ ntract.winmd</HintPa‌ th>

将此添加到您在 Visual Studio 中的项目文件中.

我希望这就是您要找的东西,无论哪种方式,您都可以访问Windows.Media"命名空间.

I would like to get track info of the current playing track in the Microsoft Groove app in my own app. I'm talking about the Groove APP and not the REST Api.

My first approach was to try and get the Windows.Media.Playback.BackgroundMediaPlayer (now obsolete) info from my own process (app). More info about the Windows.Media.Playback.BackgroundMediaPlayer in the Dev Center Documentation

The idea was to get information from BackgroundMediaPlayer.Current but this only works in the same process. And again, this is obsolete anyway, now MS recommends using the Windows.Media.Playback.MediaPlayer class, but this is also only accessible in the same process where the MediaPlayer is used.

Second approach would be getting the information from the System Media Transport Controls.

For those not familiar with the SMTC, here's what I'm talking about (the little popup when you skip/play/pause from your keyboard for example):

The article about SMTC linked above shows how to use those controls in your app, the thing I want to do is basically the exact opposite.

Does anyone have an other approach you think might work?

edit

So I found out that it might be possible by using the native ISystemMediaTransportControlsInterop interface:

https://msdn.microsoft.com/en-us/library/windows/desktop/dn892315(v=vs.85).aspx

more exactly the ISystemMediaTransportControlsInterop::GetForWindow method:

https://msdn.microsoft.com/en-us/library/windows/desktop/dn892316(v=vs.85).aspx

But I don't know how to call this method, what library to use (dll) so i can (maybe) pInvoke this in my C# app.

The docs say that this is included in the Windows 10 SDK, but I can't find out where.

Maybe I'm totally wrong and maybe I can't use this in C# (because it is a C++ interface). But my idea was that this must be compiled into a library and that I can use it by using pInvoke.

It would be much appreciated if someone can explain this to me.

解决方案

https://docs.microsoft.com/en-us/uwp/api/Windows.Media.SystemMediaTransportControls

SystemMediaTransportControls _control = SystemMediaTransportControls.GetForCurrentView();

Windows.Foundation.UniversalApiContract.winmd is the contract you require to gain access to the SMTC Class.

Reference this and you should be able to gain control.

<Reference Include="Windows.Foundation.UniversalApiContract"> <HintPath>C:Program Files (x86)Windows Kits10ReferencesWindows.Foundation.UniversalApiContract3‌​.0.0.0Windows.Found‌​ation.UniversalApiCo‌​ntract.winmd</HintPa‌​th> </Reference>

add this to your project file in visual studio.

I'm hoping this is what you were looking for, either way this will allow you access to the "Windows.Media" namespace.

这篇关于从 Microsoft Groove Music 应用获取当前播放曲目信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆