Using SystemMediaTransportControls to get current playing song info from other app

試著忘記壹切 提交于 2020-08-05 07:53:45

问题


I write a some program that should work with another player and retrieve info about current playing song. That player is written using UWP, so Windows knows what track is playing, so i can see it's name and other info when changing volume:

https://i.imgur.com/nNy16Gs.png

Things I tried:

var systemMediaControls = SystemMediaTransportControls.GetForCurrentView();

From Get current playing track info from Microsoft Groove Music app

Unfortunately, as I understand, it's just for local media, playing from my app.

Background media player doesn't helped too because of same reason.

Is it possible at all to get it from Windows? Or I should directly read memory of that player, heh?


回答1:


The screen control bar displayed by the music application is not controlled by the system but belongs to the application itself.

You don't have a way to get playing music in other music software just as you can't get files from the application folder of other applications.

Anyway, if you just want to get current song from OS, there’s no such API.

Best regards.




回答2:


I'm late to the party but I found a possible solution for you.

I use the https://www.nuget.org/packages/Microsoft.Windows.SDK.Contracts package to use Windows Runtime APIs in the .NET Framework.

Then all you have to do is:

using System;
using Windows.Media.Control;

//

var gsmtcsm = GlobalSystemMediaTransportControlsSessionManager.RequestAsync().GetAwaiter().GetResult().GetCurrentSession();
var mediaProperties = gsmtcsm.TryGetMediaPropertiesAsync().GetAwaiter().GetResult();
Console.WriteLine("{0} - {1}", mediaProperties.Artist, mediaProperties.Title);

This will result in printing the Artist and Title of the song thats currently in the System Media Transport Controls

Best regards, Luca



来源:https://stackoverflow.com/questions/57580053/using-systemmediatransportcontrols-to-get-current-playing-song-info-from-other-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!