mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 09:49:07 +00:00
delete cover art when close
This commit is contained in:
@@ -19,12 +19,14 @@ using System;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media.Animation;
|
using System.Windows.Media.Animation;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
using Meta.Vlc;
|
using Meta.Vlc;
|
||||||
using Meta.Vlc.Interop.Media;
|
using Meta.Vlc.Interop.Media;
|
||||||
using QuickLook.Annotations;
|
using QuickLook.Annotations;
|
||||||
@@ -39,8 +41,9 @@ namespace QuickLook.Plugin.VideoViewer
|
|||||||
public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChanged
|
public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
private readonly ContextObject _context;
|
private readonly ContextObject _context;
|
||||||
|
private BitmapSource _coverArt;
|
||||||
|
|
||||||
private Uri _coverArt;
|
private string _coverArtPath = string.Empty;
|
||||||
private bool _hasAudio;
|
private bool _hasAudio;
|
||||||
private bool _hasEnded;
|
private bool _hasEnded;
|
||||||
private bool _hasVideo;
|
private bool _hasVideo;
|
||||||
@@ -147,12 +150,12 @@ namespace QuickLook.Plugin.VideoViewer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uri CoverArt
|
public BitmapSource CoverArt
|
||||||
{
|
{
|
||||||
get => _coverArt;
|
get => _coverArt;
|
||||||
private set
|
private set
|
||||||
{
|
{
|
||||||
if (value == _coverArt) return;
|
if (ReferenceEquals(value, _coverArt)) return;
|
||||||
if (value == null) return;
|
if (value == null) return;
|
||||||
_coverArt = value;
|
_coverArt = value;
|
||||||
OnPropertyChanged();
|
OnPropertyChanged();
|
||||||
@@ -172,6 +175,10 @@ namespace QuickLook.Plugin.VideoViewer
|
|||||||
mediaElement?.Dispose();
|
mediaElement?.Dispose();
|
||||||
mediaElement = null;
|
mediaElement = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// delete cached cover art
|
||||||
|
if (!string.IsNullOrWhiteSpace(_coverArtPath))
|
||||||
|
File.Delete(_coverArtPath);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -245,9 +252,13 @@ namespace QuickLook.Plugin.VideoViewer
|
|||||||
if (HasVideo)
|
if (HasVideo)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var path = mediaElement.VlcMediaPlayer.Media.GetMeta(MetaDataType.ArtworkUrl);
|
var artUri = mediaElement.VlcMediaPlayer.Media.GetMeta(MetaDataType.ArtworkUrl);
|
||||||
if (!string.IsNullOrEmpty(path))
|
if (!string.IsNullOrEmpty(artUri))
|
||||||
CoverArt = new Uri(path);
|
{
|
||||||
|
var u = new Uri(artUri);
|
||||||
|
_coverArtPath = u.LocalPath;
|
||||||
|
CoverArt = u.LoadBitmapImage();
|
||||||
|
}
|
||||||
|
|
||||||
metaTitle.Text = mediaElement.VlcMediaPlayer.Media.GetMeta(MetaDataType.Title);
|
metaTitle.Text = mediaElement.VlcMediaPlayer.Media.GetMeta(MetaDataType.Title);
|
||||||
metaArtists.Text = mediaElement.VlcMediaPlayer.Media.GetMeta(MetaDataType.Artist);
|
metaArtists.Text = mediaElement.VlcMediaPlayer.Media.GetMeta(MetaDataType.Artist);
|
||||||
@@ -270,7 +281,7 @@ namespace QuickLook.Plugin.VideoViewer
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var dark = false;
|
var dark = false;
|
||||||
using (var bitmap = new Bitmap(CoverArt.LocalPath))
|
using (var bitmap = new Bitmap(CoverArt.ToBitmap()))
|
||||||
{
|
{
|
||||||
dark = bitmap.IsDarkImage();
|
dark = bitmap.IsDarkImage();
|
||||||
}
|
}
|
||||||
|
@@ -135,5 +135,15 @@ namespace QuickLook.ExtensionMethods
|
|||||||
|
|
||||||
return darks > 0.65 * sampleCount;
|
return darks > 0.65 * sampleCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BitmapImage LoadBitmapImage(this Uri source)
|
||||||
|
{
|
||||||
|
var bitmap = new BitmapImage();
|
||||||
|
bitmap.BeginInit();
|
||||||
|
bitmap.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
|
bitmap.UriSource = source;
|
||||||
|
bitmap.EndInit();
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user