Currently playing song from Windows 10 'Now Playing' card
Asked Answered
L

2

9

Is it possible to query the metadata that is displayed when playing music on Windows 10?

https://static.mcmap.net/file/mcmap/ZG-Ab5ovKRkRLw2AZV22bFljKmMva3/1q00mc.jpg

While I found information about displaying the metadata from a MediaPlayer with SMTC and such, I can't find any way for a process (which doesn't play any media itself) to simply read out that same metadata.

Leatherleaf answered 16/10, 2017 at 19:9 Comment(0)
C
9

There's a .NET Framework wrapper that's able to accomplish this called WindowsMediaController.

It does it by utilizing the Windows.SDK.Contracts package to use Windows Runtime APIs in .NET Framework.

Here's a basic implementation that will print the currently playing media:

using System;
using Windows.Media.Control;

//

public static void PrintCurrentlyPlaying()
{
   var sessionManager = GlobalSystemMediaTransportControlsSessionManager.RequestAsync().GetAwaiter().GetResult();
   var currentSession = sessionManager.GetCurrentSession();
   var mediaProperties = currentSession.TryGetMediaPropertiesAsync().GetAwaiter().GetResult();
   Console.WriteLine($"Playing {mediaProperties.Title} by {mediaProperties.Artist}");
}
Corky answered 1/8, 2020 at 16:10 Comment(0)
W
1

This currently isn't possible, as there isn't an API that I know about that offers this.

Wordy answered 17/10, 2017 at 9:10 Comment(1)
GlobalSystemMediaTransportControlsSessionManager is added by MS after this answer.Stuyvesant

© 2022 - 2024 — McMap. All rights reserved.