static async void RaiseVideoPlayerDisengaged() { await DispatchManager.RunOnDispatcherAsync(() => { try { OnVideoPlayerDisengaged?.Invoke(); } catch { // Ignore error } }); }
private static async void PlaybackList_CurrentItemChanged(MediaPlaybackList sender, CurrentMediaPlaybackItemChangedEventArgs args) { try { if (args.NewItem == null) { return; } var currentItem = sender.CurrentItem; if (currentItem == null) { return; } CheckPlaylistState(sender); syncedItem = playbackList.CurrentItem; RestorePosition(); if (CurrentEntry == null) { return; } Debug.WriteLine("Switched to episode#" + CurrentEntry.Episode.Title); if (currentItem.Source.Duration.HasValue) { CurrentEntry.Duration = currentItem.Source.Duration.Value.TotalSeconds; } else { CurrentEntry.Duration = 0; } if (LocalSettings.Instance.VideoPlayback && args.NewItem.VideoTracks.Count > 0) { videoPlayInProgess = true; RaiseVideoPlayerEngaged(); } else if (videoPlayInProgess) { videoPlayInProgess = false; RaiseVideoPlayerDisengaged(); } // Playback rate try { Player.PlaybackSession.PlaybackRate = LocalSettings.Instance.PlaySpeed / 100.0; } catch (Exception) { LocalSettings.Instance.PlaySpeed = 100; } if (!(Application.Current as App).IsInBackground && CurrentEntry != null && CurrentEntry.IsStreaming && NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable && NetworkHelper.Instance.ConnectionInformation.IsInternetOnMeteredConnection && !LocalSettings.Instance.StreamOnMetered) { await DispatchManager.RunOnDispatcherAsync(async() => { Pause(false); await App.MessageAsync(StringsHelper.StreamingIsDisabled); }); } SyncState(Player.PlaybackSession.PlaybackState); } catch (Exception ex) { App.TrackException(ex); CoreTools.ShowDebugToast(ex.Message, "PlaybackList_CurrentItemChanged"); } }
async Task ParseAsync(Windows.Data.Xml.Dom.XmlDocument document, bool notify, bool checkDownloads) { try { GetLocalImage(); var channel = document.GetElementsByTagName("channel")[0]; var tempList = new List <Episode>(); foreach (var currentItem in channel.ChildNodes) { if (currentItem.NodeName != "item") { continue; } var item = currentItem as Windows.Data.Xml.Dom.XmlElement; var episode = new Episode { Link = item.GetChildNodeTextValue("link", ""), Title = item.GetChildNodeTextValue("title", "").Sanitize(), Subtitle = item.GetChildNodeTextValue("itunes:subtitle", "").Sanitize(), Author = item.GetChildNodeTextValue("itunes:author", "").Sanitize(), Summary = item.GetChildNodeTextValue("description", "").SanitizeAsHTML(), Enclosure = item.GetChildNodeAttribute("enclosure", "url", ""), PictureUrl = item.GetChildNodeAttribute("itunes:image", "href", ""), DeclaredDuration = item.GetChildNodeTextValue("itunes:duration", ""), Keywords = item.GetChildNodeTextValue("itunes:keywords", ""), PublicationDate = item.GetChildNodeTextValue("pubDate", "").TryParseAsDateTime(), PodcastFeedUrl = FeedUrl }; var length = item.GetChildNodeAttribute("enclosure", "length", ""); double estimatedLength; if (Double.TryParse(length, out estimatedLength)) { episode.EstimatedFileSize = estimatedLength; } if (!episode.DeclaredDuration.Contains(":")) { episode.DeclaredDuration = ""; } var itunesSummary = item.GetChildNodeTextValue("itunes:summary", "").SanitizeAsHTML(); if (itunesSummary.Length > episode.Summary.Length) { episode.Summary = itunesSummary; } var contentSummary = item.GetChildNodeTextValue("content:encoded", "").SanitizeAsHTML(); if (contentSummary.Length > episode.Summary.Length) { episode.Summary = contentSummary; } if (string.IsNullOrEmpty(episode.Author)) { episode.Author = Title; } if (string.IsNullOrEmpty(episode.Enclosure)) { episode.Enclosure = episode.Link; } if (string.IsNullOrEmpty(episode.PictureUrl)) { episode.PictureUrl = LocalImage; } episode.Clean(); tempList.Add(episode); } var addedEpisodes = new List <Episode>(); var indexToInject = 0; foreach (var episode in tempList.OrderByDescending(e => e.PublicationDate)) { var inLibraryEpisode = Episodes.FirstOrDefault(e => e.Enclosure == episode.Enclosure); if (inLibraryEpisode != null) { inLibraryEpisode.Author = episode.Author; inLibraryEpisode.DeclaredDuration = episode.DeclaredDuration; inLibraryEpisode.Keywords = episode.Keywords; inLibraryEpisode.Link = episode.Link; inLibraryEpisode.PictureUrl = episode.PictureUrl; inLibraryEpisode.PodcastFeedUrl = episode.PodcastFeedUrl; inLibraryEpisode.Title = episode.Title; inLibraryEpisode.Subtitle = episode.Subtitle; inLibraryEpisode.Summary = episode.Summary; inLibraryEpisode.PublicationDate = episode.PublicationDate; inLibraryEpisode.EstimatedFileSize = episode.EstimatedFileSize; continue; } await DispatchManager.RunOnDispatcherAsync(() => { Episodes.Insert(indexToInject, episode); }); indexToInject++; addedEpisodes.Add(episode); if (notify && IsInLibrary && LocalSettings.Instance.Notifications) { Messenger.Notify(string.Format(LocalSettings.Instance.NotificationMessage, episode.Title), Title, "", LocalImage); } } if (addedEpisodes.Count > 0 && IsInLibrary && AppSettings.Instance.AutomaticallyAddNewEpisodeToPlaylist) { await DispatchManager.RunOnDispatcherAsync(() => { var reversedAddedEpisodes = addedEpisodes.OrderBy(e => e.PublicationDate).ToList(); if (Playlist.CurrentPlaylist != null) { Playlist.CurrentPlaylist.AddEpisodes(reversedAddedEpisodes); } else { Playlist.EpisodesToAdd.AddRange(reversedAddedEpisodes); } }); } LocalSettings.Instance.NewEpisodesCount += addedEpisodes.Count; if (checkDownloads) { CheckForAutomaticDownloads(); } if (toExecuteWhenReady != null) { toExecuteWhenReady(); toExecuteWhenReady = null; } } catch { await Messenger.ErrorAsync(StringsHelper.Error_UnableToParseRSS + " (" + Title + ")"); } }