private async void MediaPlaybackList_CurrentItemChanged(MediaPlaybackList sender, CurrentMediaPlaybackItemChangedEventArgs args) { await UIDispatcher.RunAsync(CoreDispatcherPriority.High, () => { var newItem = PlaybackList.Where(x => x.SourceObject == args.NewItem).FirstOrDefault(); var oldItem = PlaybackList.Where(x => x.SourceObject == args.OldItem).FirstOrDefault(); if (newItem != null) { newItem.State = "Playing"; PlayingItemChanged?.Invoke(null, newItem); } if (oldItem != null) { oldItem.State = string.Empty; } }); }
private void BuildMediaPlaybackList() { for (int i = 1; i < 5; i++) { string file = $"ms-appx:///Assets/mp3/0{i}.mp3"; MediaSource source = MediaSource.CreateFromUri(new Uri(file, UriKind.RelativeOrAbsolute)); MediaPlaybackItem item = new MediaPlaybackItem(source); MediaItemDisplayProperties displayProperty = item.GetDisplayProperties(); displayProperty.Type = MediaPlaybackType.Music; displayProperty.MusicProperties.Title = $"0{i}.mp3"; displayProperty.MusicProperties.AlbumArtist = "JJ"; displayProperty.Thumbnail = RandomAccessStreamReference.CreateFromUri(new Uri($"ms-appx:///Assets/mp3/0{i}.jpg", UriKind.RelativeOrAbsolute)); item.ApplyDisplayProperties(displayProperty); PlaybackList.Add(new MediaPlaybackItemDataWrapper(item)); MediaPlaybackList.Items.Add(item); } }