(UWP)如何激活“任务栏迷你播放器".像在Groove中 [英] (UWP) How to activate the "Taskbar Miniplayer" like in Groove

查看:48
本文介绍了(UWP)如何激活“任务栏迷你播放器".像在Groove中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的应用程序使用BackgroundMediaPlayer在后台播放音频.现在我看到了这些按钮:

I use the BackgroundMediaPlayer for my App to play Audio in the Background. Now i see these buttons:

我如何激活它们?

推荐答案

为了使任务栏中的媒体控件正常工作,您需要从前台应用程序和后台任务加载并配置SystemMediaTransportControls.如果仅从后台任务执行此操作,则将显示控件,但它们将保持禁用状态.

In order to make the media controls from the taskbar to work, you need to load and configure the SystemMediaTransportControls from the foreground application AND the background task. If you are doing it only from the background task, the controls will be displayed but they will remain disabled.

在前台应用程序中,您应该具有以下代码:

In your foreground application, you should have the following code:

var smtc = SystemMediaTransportControls.GetForCurrentView();
smtc.ButtonPressed += smtc_ButtonPressed;
smtc.PropertyChanged += smtc_PropertyChanged;
smtc.IsEnabled = true;
smtc.IsPauseEnabled = true;
smtc.IsPlayEnabled = true;
smtc.IsNextEnabled = true;
smtc.IsPreviousEnabled = true;

在后台任务中,您应该具有:

And in the background task, you should have :

smtc = BackgroundMediaPlayer.Current.SystemMediaTransportControls;
smtc.ButtonPressed += smtc_ButtonPressed;
smtc.PropertyChanged += smtc_PropertyChanged;
smtc.IsEnabled = true;
smtc.IsPauseEnabled = true;
smtc.IsPlayEnabled = true;
smtc.IsNextEnabled = true;
smtc.IsPreviousEnabled = true;

请注意,获取控件实例的API不相同:
SystemMediaTransportControls.GetForCurrentView()在前台应用程序和

Beware that the API to get the control instance is not the same:
SystemMediaTransportControls.GetForCurrentView() in the foreground app and BackgroundMediaPlayer.Current.SystemMediaTransportControls in the background task.

您将必须在两个(前景+背景)中支持按钮按下事件

You will have to support the button pressed event in the two (foreground + background)

这篇关于(UWP)如何激活“任务栏迷你播放器".像在Groove中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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