diff --git a/Unosquare.FFME.Windows.Sample/AppCommands.cs b/Unosquare.FFME.Windows.Sample/AppCommands.cs index 8409267ec..29fa3c4d4 100644 --- a/Unosquare.FFME.Windows.Sample/AppCommands.cs +++ b/Unosquare.FFME.Windows.Sample/AppCommands.cs @@ -164,8 +164,11 @@ internal AppCommands() { if (arg is CustomPlaylistEntry entry) { - App.ViewModel.Playlist.Entries.RemoveEntryByMediaSource(entry.MediaSource); - App.ViewModel.Playlist.Entries.SaveEntries(); + if (Uri.TryCreate(entry.MediaSource, UriKind.RelativeOrAbsolute, out var mediaSource)) + { + App.ViewModel.Playlist.Entries.RemoveEntryByMediaSource(mediaSource); + App.ViewModel.Playlist.Entries.SaveEntries(); + } } })); } diff --git a/Unosquare.FFME.Windows.Sample/Foundation/CustomPlaylistEntryCollection.cs b/Unosquare.FFME.Windows.Sample/Foundation/CustomPlaylistEntryCollection.cs index f4fa3740e..d22db3439 100644 --- a/Unosquare.FFME.Windows.Sample/Foundation/CustomPlaylistEntryCollection.cs +++ b/Unosquare.FFME.Windows.Sample/Foundation/CustomPlaylistEntryCollection.cs @@ -44,11 +44,11 @@ public CustomPlaylistEntryCollection(PlaylistViewModel viewModel) /// /// The media URL. /// The playlist entry or null if not found. - public CustomPlaylistEntry FindEntryByMediaSource(string mediaSource) + public CustomPlaylistEntry FindEntryByMediaSource(Uri mediaSource) { lock (SyncRoot) { - var lookupMediaSource = mediaSource?.Trim() ?? string.Empty; + var lookupMediaSource = mediaSource?.OriginalString ?? string.Empty; foreach (var entry in this) { if (lookupMediaSource.Equals(entry.MediaSource, StringComparison.OrdinalIgnoreCase)) @@ -68,7 +68,7 @@ public void AddOrUpdateEntry(Uri mediaSource, MediaInfo info) { lock (SyncRoot) { - var entry = FindEntryByMediaSource(mediaSource.OriginalString); + var entry = FindEntryByMediaSource(mediaSource); if (entry == null) { // Create a new entry with default values @@ -130,13 +130,12 @@ public void AddOrUpdateEntry(Uri mediaSource, MediaInfo info) /// Sets the entry thumbnail. /// Deletes the prior thumbnail file is found or previously set. /// - /// The media info. + /// The media info. /// The bitmap. - public void AddOrUpdateEntryThumbnail(MediaInfo info, BitmapDataBuffer bitmap) + public void AddOrUpdateEntryThumbnail(Uri mediaSource, BitmapDataBuffer bitmap) { lock (SyncRoot) { - var mediaSource = info.MediaSource; var entry = FindEntryByMediaSource(mediaSource); if (entry == null) return; @@ -160,7 +159,7 @@ public void AddOrUpdateEntryThumbnail(MediaInfo info, BitmapDataBuffer bitmap) /// Removes the entry. /// /// The media source. - public void RemoveEntryByMediaSource(string mediaSource) + public void RemoveEntryByMediaSource(Uri mediaSource) { lock (SyncRoot) { diff --git a/Unosquare.FFME.Windows.Sample/ViewModels/PlaylistViewModel.cs b/Unosquare.FFME.Windows.Sample/ViewModels/PlaylistViewModel.cs index 0b599bdd7..e3ee1b712 100644 --- a/Unosquare.FFME.Windows.Sample/ViewModels/PlaylistViewModel.cs +++ b/Unosquare.FFME.Windows.Sample/ViewModels/PlaylistViewModel.cs @@ -194,10 +194,8 @@ private void OnRenderingVideo(object sender, RenderingVideoEventArgs e) if (HasTakenThumbnail) return; var state = e.EngineState; - var mediaElement = sender as MediaElement; - var info = mediaElement?.MediaInfo; - if (string.IsNullOrWhiteSpace(info?.MediaSource)) + if (state.Source == null) return; if (!state.HasMediaEnded && state.Position.TotalSeconds < snapshotPosition && @@ -205,7 +203,7 @@ private void OnRenderingVideo(object sender, RenderingVideoEventArgs e) return; HasTakenThumbnail = true; - Entries.AddOrUpdateEntryThumbnail(info, e.Bitmap); + Entries.AddOrUpdateEntryThumbnail(state.Source, e.Bitmap); Entries.SaveEntries(); } }