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}");
}