Skip to content

Commit

Permalink
fixing minor issues with playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
mariodivece committed Nov 12, 2019
1 parent 3892e77 commit 37327b6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
7 changes: 5 additions & 2 deletions Unosquare.FFME.Windows.Sample/AppCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public CustomPlaylistEntryCollection(PlaylistViewModel viewModel)
/// </summary>
/// <param name="mediaSource">The media URL.</param>
/// <returns>The playlist entry or null if not found.</returns>
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))
Expand All @@ -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
Expand Down Expand Up @@ -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.
/// </summary>
/// <param name="info">The media info.</param>
/// <param name="mediaSource">The media info.</param>
/// <param name="bitmap">The bitmap.</param>
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;

Expand All @@ -160,7 +159,7 @@ public void AddOrUpdateEntryThumbnail(MediaInfo info, BitmapDataBuffer bitmap)
/// Removes the entry.
/// </summary>
/// <param name="mediaSource">The media source.</param>
public void RemoveEntryByMediaSource(string mediaSource)
public void RemoveEntryByMediaSource(Uri mediaSource)
{
lock (SyncRoot)
{
Expand Down
6 changes: 2 additions & 4 deletions Unosquare.FFME.Windows.Sample/ViewModels/PlaylistViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,16 @@ 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 &&
(!state.PlaybackEndTime.HasValue || state.PlaybackEndTime.Value.TotalSeconds > snapshotPosition))
return;

HasTakenThumbnail = true;
Entries.AddOrUpdateEntryThumbnail(info, e.Bitmap);
Entries.AddOrUpdateEntryThumbnail(state.Source, e.Bitmap);
Entries.SaveEntries();
}
}
Expand Down

0 comments on commit 37327b6

Please sign in to comment.