user4149157
user4149157

Reputation:

Get current playing track info from Microsoft Groove Music app

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

enter image description here

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.

Upvotes: 15

Views: 3259

Answers (1)

Enoons_
Enoons_

Reputation: 21

https://learn.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 Kits\10\References\Windows.Foundation.UniversalApiContract\3‌​.0.0.0\Windows.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.

Upvotes: 2

Related Questions