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

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

问题描述

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

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.

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

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

想法是从BackgroundMediaPlayer.Current获取信息,但这仅在相同的过程中起作用.再说一次,这已经过时了,现在MS建议使用Windows.Media.Playback.MediaPlayer类,但这也只能在使用MediaPlayer的相同过程中进行访问.

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.

第二种方法是从对于那些不熟悉SMTC的人,这就是我在说的(例如,当您从键盘上跳过/播放/暂停时会弹出的小弹出窗口):

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):

上面链接的有关SMTC的文章显示了如何在您的应用程序中使用这些控件,我要做的基本上与之相反.

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?

编辑

所以我发现使用本机的ISystemMediaTransportControlsInterop界面可能是可行的:

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

更准确地是ISystemMediaTransportControlsInterop::GetForWindow方法:

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

但是我不知道如何调用此方法,要使用哪个库(dll),以便我可以(也许)p在我的C#应用​​程序中调用它.

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.

文档说,这已包含在Windows 10 SDK中,但我找不到位置.

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

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

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.

推荐答案

SystemMediaTransportControls _control = SystemMediaTransportControls.GetForCurrentView();

Windows.Foundation.UniversalApiContract.winmd是获得对SMTC类的访问权所需的合同.

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 Kits\10\References\Windows.Foundation.UniversalApiContract\3‌​.0.0.0\Windows.Found‌​ation.UniversalApiCo‌​ntract.winmd</HintPa‌​th> </Reference>

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

add this to your project file in visual studio.

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

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

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

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