SystemMediaTransportControls - 设置属性不起作用

SystemMediaTransportControls - setting properties not working

我正在尝试在后台音频应用程序中使用 SystemMediaTransportControls。我正在使用 MediaPlayer class 播放音频。设置音乐属性、缩略图似乎都可以正常工作,但设置控制按钮(即 "next" 按钮)根本不起作用。我的用例有些独特,因为我无法立即获得完整的播放列表,下一首曲目只能通过内部方法调用获得。

这是我正在做的事情:

这部分工作正常,音量控制正确显示所有音频信息和缩略图:

var playbackItem = new MediaPlaybackItem(source);
var displayProperties = playbackItem.GetDisplayProperties();
displayProperties.Type = Windows.Media.MediaPlaybackType.Music;
displayProperties.Thumbnail = RandomAccessStreamReference.CreateFromUri(new Uri(_currentTrack.AlbumArtUrl));
displayProperties.MusicProperties.AlbumArtist = displayProperties.MusicProperties.Artist = _currentTrack.Artist;
displayProperties.MusicProperties.Title = _currentTrack.SongTitle;
displayProperties.MusicProperties.AlbumTitle = _currentTrack.Album;
playbackItem.CanSkip = true;
playbackItem.ApplyDisplayProperties(displayProperties);
_player.Source = playbackItem;

这部分不工作,"Next" 按钮仍然被禁用,"Record" 按钮没有显示。

var smtc = _player.SystemMediaTransportControls;
smtc.ButtonPressed += OnSMTCButtonPressed;
smtc.IsEnabled = true;
smtc.IsNextEnabled = true;
smtc.IsRecordEnabled = true;

我一直在尝试在线寻找答案,但找不到任何有用的信息。任何答案表示赞赏。

在 UWP 中,除了 SMTC,还有类似 CommandManager 的东西 - 要正确使用 SMTC,您必须禁用它。只需输入行:

mediaPlayer.CommandManager.IsEnabled = false;

初始化播放器后,它应该可以工作。您可以在 MSDN:

找到更多信息

If you are using MediaPlayer to play media, you can get an instance of the SystemMediaTransportControls class by accessing the MediaPlayer.SystemMediaTransportControls property. If you are going to manually control the SMTC, you should disable the automatic integration provided by MediaPlayer by setting the CommandManager.IsEnabled property to false.