handle TagLib exception

This commit is contained in:
Paddy Xu
2018-01-21 16:11:20 +02:00
parent 35c22db10c
commit 5667f98a01

View File

@@ -146,21 +146,30 @@ namespace QuickLook.Plugin.VideoViewer
if (ShowVideo) if (ShowVideo)
return; return;
using (var h = File.Create(path)) try
{ {
metaTitle.Text = h.Tag.Title; using (var h = File.Create(path))
metaArtists.Text = h.Tag.FirstPerformer; {
metaAlbum.Text = h.Tag.Album; metaTitle.Text = !string.IsNullOrWhiteSpace(h.Tag.Title) ? h.Tag.Title : Path.GetFileName(path);
metaArtists.Text = h.Tag.FirstPerformer;
metaAlbum.Text = h.Tag.Album;
//var cs = h.Tag.Pictures.FirstOrDefault(p => p.Type == TagLib.PictureType.FrontCover); //var cs = h.Tag.Pictures.FirstOrDefault(p => p.Type == TagLib.PictureType.FrontCover);
var cs = h.Tag.Pictures.FirstOrDefault(); var cs = h.Tag.Pictures.FirstOrDefault();
if (cs != default(IPicture)) if (cs != default(IPicture))
using (var ms = new MemoryStream(cs.Data.Data)) using (var ms = new MemoryStream(cs.Data.Data))
{ {
CoverArt = BitmapFrame.Create(ms, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); CoverArt = BitmapFrame.Create(ms, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
DetermineTheme(); DetermineTheme();
} }
}
} }
catch (Exception e)
{
metaTitle.Text = Path.GetFileName(path);
metaArtists.Text = metaAlbum.Text = string.Empty;
}
metaArtists.Visibility = string.IsNullOrEmpty(metaArtists.Text) metaArtists.Visibility = string.IsNullOrEmpty(metaArtists.Text)
? Visibility.Collapsed ? Visibility.Collapsed
: Visibility.Visible; : Visibility.Visible;