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();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…