Beispiel #1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (Provider == null || this.ArtworkBrushFactory == null)
            {
                return(null);
            }
            if (double.IsNaN(this.Width) || double.IsNaN(this.Height) || this.Width == 0 || this.Height == 0)
            {
                return(null);
            }
            var fileName = default(string);

            if (value is string)
            {
                fileName = (string)value;
                if (!this.ShowPlaceholder && !FileSystemHelper.IsLocalPath(fileName))
                {
                    return(null);
                }
            }
            else if (value is IFileData)
            {
                fileName = Provider.Find(
                    (IFileData)value,
                    ArtworkType.FrontCover
                    );
            }
            var size = global::System.Convert.ToInt32(Math.Max(this.Width, this.Height));

            return(this.ArtworkBrushFactory.Create(
                       fileName,
                       size,
                       size
                       ));
        }
Beispiel #2
0
        private static async Task <bool> ReadLoose(TagLibMetaDataSource source, IList <MetaDataItem> metaDatas, File file)
        {
            var types = ArtworkType.None;

            try
            {
                foreach (var type in new[] { ArtworkType.FrontCover, ArtworkType.BackCover })
                {
                    if (!ArtworkTypes.HasFlag(type))
                    {
                        continue;
                    }
                    var value = ArtworkProvider.Find(file.Name, type);
                    if (!string.IsNullOrEmpty(value) && global::System.IO.File.Exists(value))
                    {
                        if (source.CopyImages.Value)
                        {
                            value = await ImportImage(value, value, false).ConfigureAwait(false);
                        }
                        metaDatas.Add(new MetaDataItem()
                        {
                            Name  = Enum.GetName(typeof(ArtworkType), type),
                            Value = value,
                            Type  = MetaDataItemType.Image
                        });
                        if (ArtworkTypes.HasFlag(types |= type))
                        {
                            //We have everything we need.
                            return(true);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Write(typeof(ImageManager), LogLevel.Warn, "Failed to read pictures: {0} => {1}", file.Name, e.Message);
            }
            return(types != ArtworkType.None);
        }
Beispiel #3
0
        public async Task Refresh()
        {
            var fileName     = default(string);
            var outputStream = PlaybackManager.CurrentStream;

            if (outputStream != null)
            {
                fileName = ArtworkProvider.Find(
                    outputStream.PlaylistItem,
                    ArtworkType.FrontCover
                    );
            }
            if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
            {
                var source = ImageLoader.Load(
                    ThemeLoader.Theme.Id,
                    () => ThemeLoader.Theme.ArtworkPlaceholder,
                    true
                    );
                var brush = new ImageBrush(source)
                {
                    Stretch = Stretch.Uniform
                };
                brush.Freeze();
                await Windows.Invoke(() =>
                {
                    this.Background         = brush;
                    this.IsComponentEnabled = false;
                }).ConfigureAwait(false);
            }
            else
            {
                var source = ImageLoader.Load(
                    fileName,
                    fileName,
                    0,
                    0,
                    true
                    );
                await Windows.Invoke(() =>
                {
                    this.Background = new ImageBrush(source)
                    {
                        Stretch = Stretch.Uniform
                    };
                    this.IsComponentEnabled = true;
                }).ConfigureAwait(false);
            }
        }