Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
825 views
Welcome To Ask or Share your Answers For Others

1 Answer

How to display artist and song name:

Get the Microsoft.Windows.SDK.Contracts package if you're not developing a WinRT app.

(Visual Studio) In your NuGet Package Manager settings (Tools->NuGet Package Manager->Package Manager Settings) you need to have 'PackageManagementDefault package management format' set to 'PackageReference'

If you've done that, the package should show up in your References. If that isn't the case, you need to deinstall the package and its dependencies and try again.

Here's example code:

using System;
using System.Threading.Tasks;
using Windows.Media.Control;

public static class Program {
    public static async Task Main(string[] args) {
        var gsmtcsm = await GetSystemMediaTransportControlsSessionManager();
        var mediaProperties = await GetMediaProperties(gsmtcsm.GetCurrentSession());

        Console.WriteLine("{0} - {1}", mediaProperties.Artist, mediaProperties.Title);

        Console.WriteLine("Press any key to quit..");
        Console.ReadKey(true);
    }

    private static async Task<GlobalSystemMediaTransportControlsSessionManager> GetSystemMediaTransportControlsSessionManager() =>
        await GlobalSystemMediaTransportControlsSessionManager.RequestAsync();

    private static async Task<GlobalSystemMediaTransportControlsSessionMediaProperties> GetMediaProperties(GlobalSystemMediaTransportControlsSession session) =>
        await session.TryGetMediaPropertiesAsync();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...