答案 0 :(得分:1)
为了使任务栏中的媒体控件正常工作,您需要从前台应用程序和后台任务加载和配置SystemMediaTransportControls。如果您仅从后台任务执行此操作,则会显示控件但它们将保持禁用状态。
在前台应用程序中,您应该拥有以下代码:
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;
在后台任务中,您应该:
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()
在前台应用程序中,BackgroundMediaPlayer.Current.SystemMediaTransportControls在后台任务中。
您必须支持两个(前景+背景)
中的按钮按下事件答案 1 :(得分:0)
那是System Media Transport Controls,您应该添加代码来处理点击事件 这是官方样本:
public MainPage()
{
this.InitializeComponent();
// Hook up app to system transport controls.
systemMediaControls = SystemMediaTransportControls.GetForCurrentView();
systemMediaControls.ButtonPressed += SystemControls_ButtonPressed;
// Register to handle the following system transpot control buttons.
systemMediaControls.IsPlayEnabled = true;
systemMediaControls.IsPauseEnabled = true;
}
async void SystemControls_ButtonPressed(SystemMediaTransportControls sender,
SystemMediaTransportControlsButtonPressedEventArgs args)
{
switch (args.Button)
{
case SystemMediaTransportControlsButton.Play:
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
mediaElement.Play();
});
break;
case SystemMediaTransportControlsButton.Pause:
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
mediaElement.Pause();
});
break;
default:
break;
}
}