我一直很难在我的wp8.1应用中显示SystemMediaTransportControls
,不幸的是它无法正常工作。
这是场景,我添加了Windows Phone App Project,然后添加了Windows运行时组件(Windows Phone)。我在Myproject中引用了Runtime Component,然后在manifest中添加了Audio作为后台任务。
一切似乎工作正常,媒体在后台播放,但SystemMediaTransportControls
不显示。下面是我在BackgroundTask中运行方法的代码
public void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("Background Audio Task " + taskInstance.Task.Name + " starting...");
taskInstance.Canceled += TaskInstance_Canceled;
//taskInstance.Task.Completed += Taskcompleted;
systemmediatransportcontrol = SystemMediaTransportControls.GetForCurrentView();
systemmediatransportcontrol.ButtonPressed += systemmediatransportcontrol_ButtonPressed;
systemmediatransportcontrol.PropertyChanged += systemmediatransportcontrol_PropertyChanged;
systemmediatransportcontrol.IsEnabled = true;
systemmediatransportcontrol.IsPauseEnabled = true;
systemmediatransportcontrol.IsPlayEnabled = true;
systemmediatransportcontrol.IsNextEnabled = true;
systemmediatransportcontrol.IsPreviousEnabled = true;
BackgroundMediaPlayer.Current.CurrentStateChanged += Current_CurrentStateChanged;
BackgroundMediaPlayer.MessageReceivedFromForeground += BackgroundMediaPlayer_MessageReceivedFromForeground;
Debug.WriteLine(systemmediatransportcontrol.IsEnabled.ToString());
ValueSet message = new ValueSet();
message.Add("backgroundStarted", "1");
BackgroundMediaPlayer.SendMessageToForeground(message);
BackgroundTaskStarted.Set();
deferral = taskInstance.GetDeferral();
}
在这个问题上工作了两天,这给我带来了很多麻烦。问题是,为什么SystemMediaTransportControls
没有显示?
答案 0 :(得分:1)
使用SystemMediaTransportControls.DisplayUpdater设置MusicProperties。 MusicProperties的类型为MusicDisplayProperties,包括歌曲标题和歌曲艺术家等属性。 在轨道更改中更新此内容:
systemmediatransportcontrol.PlaybackStatus = MediaPlaybackStatus.Playing;
systemmediatransportcontrol.DisplayUpdater.Type = MediaPlaybackType.Music;
systemmediatransportcontrol.DisplayUpdater.MusicProperties.Title = "<Track_Name>";
systemmediatransportcontrol.DisplayUpdater.MusicProperties.Artist = "<Artist_Name>";
systemmediatransportcontrol.DisplayUpdater.Update();