static void MoveTo(PlaylistEntry entry) { if (playbackList != null) { SaveCurrentPosition(); var index = playbackList.Items.IndexOf(entry.AssociatedPlaybackItem); if (index >= 0 && playbackList.CurrentItemIndex != index && index < playbackList.Items.Count) { Debug.WriteLine("Moving to:" + index); try { trackedPosition = 0; SyncState(MediaPlaybackState.Buffering); playbackList.MoveTo((uint)index); } catch (Exception ex) { CoreTools.ShowDebugToast(ex.Message, "MoveTo"); } } } }
public void MoveEntryDown(PlaylistEntry entry) { var index = GetEntryIndex(entry); var savedCurrentEpisode = CurrentEpisode; index++; if (index >= Entries.Count) { return; } RemoveEntry(entry); AddEpisode(entry.Episode, index); CurrentEntry = GetEntryForEpisode(savedCurrentEpisode); }
public void MoveEntryUp(PlaylistEntry entry) { var index = GetEntryIndex(entry); var savedCurrentEpisode = CurrentEpisode; index--; if (index < 0) { return; } RemoveEntry(entry); AddEpisode(entry.Episode, index); CurrentEntry = GetEntryForEpisode(savedCurrentEpisode); }
public static void RemoveFromSource(PlaylistEntry entry) { if (playbackList != null) { if (entry == null) { return; } playbackList.Items.Remove(entry.AssociatedPlaybackItem); if (playbackList.Items.Count == 0) { Player.Source = null; playbackList = null; } } }
public void AddEpisodes(IList <Episode> episodes, int?newIndex = null) { if (episodes.Count == 0) { return; } var entriesToAdd = new List <PlaylistEntry>(); foreach (var episode in episodes) { var entry = GetEntryForEpisode(episode); if (entry != null) { continue; } entry = new PlaylistEntry { Enclosure = episode.Enclosure, Position = episode.Position }; episode.IsPlayed = false; entriesToAdd.Add(entry); } if (entriesToAdd.Count > 0) { Entries.AddRange(entriesToAdd); } RaisePropertyChanged(nameof(CanGoNext)); RaisePropertyChanged(nameof(CanGoPrev)); if (newIndex.HasValue) { CurrentIndex = newIndex.Value; } if (CurrentIndex == -1) { CurrentIndex = 0; } }
static async Task AddSourceToPlaylistAsync(PlaylistEntry entry, int?index = null) { var source = await entry.GetSourceAsync(); if (source == null) { return; } source.CustomProperties["entry"] = JsonConvert.SerializeObject(entry); var item = new MediaPlaybackItem(source); var displayInfo = item.GetDisplayProperties(); displayInfo.MusicProperties.Artist = entry.Episode.Author; displayInfo.MusicProperties.AlbumArtist = entry.Episode.Author; displayInfo.MusicProperties.Title = entry.Episode.Title; displayInfo.MusicProperties.AlbumTitle = entry.PodcastTitle ?? ""; displayInfo.Type = MediaPlaybackType.Music; try { var albumArtUri = new Uri(entry.Episode.PictureUrl); displayInfo.Thumbnail = RandomAccessStreamReference.CreateFromUri(albumArtUri); } catch { // Ignore error. Uri could be malformed or weird. } item.ApplyDisplayProperties(displayInfo); lock (Player) { if (index.HasValue && playbackList.Items.Count > index.Value) { playbackList.Items.Insert(index.Value, item); } else { playbackList.Items.Add(item); } } entry.AssociatedPlaybackItem = item; }
public void RemoveEntry(PlaylistEntry entry) { DispatchManager.RunOnDispatcher(() => { if (entry == null) { return; } var currentEntry = CurrentEntry; var previousIndex = CurrentIndex; if (currentEntry == entry) { if (previousIndex + 1 < Entries.Count) { currentEntry = Entries[previousIndex + 1]; } else if (previousIndex > 0) { currentEntry = Entries[previousIndex - 1]; } } Entries.Remove(entry); if (Entries.Count == 0) { CurrentIndex = -1; } else { CurrentIndex = Entries.IndexOf(currentEntry); if (previousIndex == CurrentIndex) { ForceBindingRefresh(); } } }); }
public static void SaveCurrentPosition(PlaylistEntry currentEntry = null, double?currentPosition = null, bool force = false) { try { if (!currentPosition.HasValue) { currentPosition = Position; } if (currentEntry == null) { currentEntry = CurrentEntry; } if (!force) { if (Playlist.CurrentPlaylist == null || playbackList?.CurrentItem == null || previousState != MediaPlaybackState.Playing) { return; } } if (currentEntry != null && currentEntry.Duration > 1 && currentPosition > 1) { // Debug.WriteLine("SaveCurrentPosition to " + currentEntry.Episode.Title + "(" + currentPosition + ")"); currentEntry.Position = currentPosition.Value; if ((currentEntry.Duration >= currentPosition) && (currentPosition / currentEntry.Duration) > 0.95 && currentEntry.Episode != null) { currentEntry.Episode.IsPlayed = true; } } } catch (Exception ex) { App.TrackException(ex); CoreTools.ShowDebugToast(ex.Message, "SaveCurrentPosition"); } }
public PlaylistEntry AddEpisode(Episode episode, int?index = null) { var entry = GetEntryForEpisode(episode); if (entry != null) { return(entry); } entry = new PlaylistEntry { Enclosure = episode.Enclosure, Position = episode.Position }; episode.IsPlayed = false; if (index.HasValue) { Entries.Insert(index.Value, entry); } else { Entries.Add(entry); } RaisePropertyChanged(nameof(CanGoNext)); RaisePropertyChanged(nameof(CanGoPrev)); if (CurrentIndex == -1) { CurrentIndex = 0; } return(entry); }
public int GetEntryIndex(PlaylistEntry entry) { return(Entries.IndexOf(entry)); }