当前正在播放来自 Windows 10“正在播放"卡的歌曲 [英] Currently playing song from Windows 10 'Now Playing' card

查看:33
本文介绍了当前正在播放来自 Windows 10“正在播放"卡的歌曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以查询在 Windows 10 上播放音乐时显示的元数据?

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

虽然我找到了有关使用 SMTC 等从 MediaPlayer 显示元数据的信息,但我找不到任何方法让进程(它本身不播放任何媒体)简单地读出相同的元数据.

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.

推荐答案

有一个 .NET Framework 包装器可以完成此任务,称为 WindowsMediaController.

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

它通过使用 Windows.SDK.Contracts 包来实现在 .NET Framework 中使用 Windows 运行时 API.

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

这篇关于当前正在播放来自 Windows 10“正在播放"卡的歌曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆