问题描述
我想为 Windows 10 开发一个音乐应用程序,我对 Groove Music 提供的音量栏旁边的界面很好奇.我试过谷歌搜索来获取更多关于它的信息,但我没有任何成功.当我在 Groove Music 中播放音乐并提高或降低音量时,当前歌曲的名称以及艺术家和专辑插图会出现在音量指示器旁边的音乐控件中:
I want to develop a music app for Windows 10 and I'm curious about the interface provided by Groove Music next to the volume bar. I've tried Googling to get more information about it but I haven't had any success whatsoever. When I'm playing music in Groove Music and I raise or lower the volume, the name as well as the artist and album artwork of the current song show up with music controls next to the volume indicator this:
我想知道如何在我自己的应用程序中创建这个对话框,以及我必须研究哪些 Windows API.
I was wondering how I could create this dialog in my own app and what windows API's I'd have to look into.
推荐答案
即使 @Stamos,因为我发现实际上可以从原生 Windows 应用程序(不仅仅是通用应用程序)中使用 SystemMediaTransportControls
.
I'm going to add my input to this even though there is a great answer already by @Stamos, because I've found that it is actually possible to use SystemMediaTransportControls
from a native windows app (not only a universal app).
首先,它仍然需要对通用 winmd
文件的引用,因此它只能在 Win10 上运行.它们将位于 10 sdk 中,您可以通过常规的 Add Reference ->浏览
但您可能需要将对话框右下角的过滤器更改为所有文件"才能显示它们.它们可以在我的 PC 上找到:
First thing, it does still require a reference to the universal winmd
files, so it will only work on Win10. They will be located in the 10 sdk, and you can add them via the regular Add Reference -> Browse
but you may need to change the filter on the bottom right of the dialog to "All Files" for them to show up. They are found here on my PC:
Windows.Foundation.UniversalApiContract
:
C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\1.0.0.0\Windows.Foundation.UniversalApiContract.winmdWindows.Foundation.FoundationContract
:
C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.FoundationContract\2.0.0.0\Windows.Foundation.FoundationContract.winmd
获得必要的引用后,您将遇到另一个问题 - 您无法通过通常的 SystemMediaTransportControls.GetForCurrentView();
访问传输控件(它会抛出异常),因为你实际上没有一个普遍的观点.使用以下方法可以缓解这种情况:
After you have the necessary references, you'll run into another problem - you can't access the transport controls via the usual SystemMediaTransportControls.GetForCurrentView();
(it will throw an exception) because you don't actually have a universal view. This is alleviated by using the following:
SystemMediaTransportControls systemControls =
BackgroundMediaPlayer.Current.SystemMediaTransportControls;
在此之后,您可以随意使用任何在线示例或 Stamos 的答案.
After this, feel free to use any of the samples online or Stamos' answer.
这篇关于与“系统范围"交互媒体播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!