public static ImageSource CreateFanArtImageSource(object source, int width, int height)
        {
            MediaItem mediaItem = source as MediaItem;

            if (mediaItem == null)
            {
                return(null);
            }
            FanArtConstants.FanArtMediaType mediaType = FanArtConstants.FanArtMediaType.Undefined;
            // Special handling for ImageThumbs that might require rotation
            if (mediaItem.Aspects.ContainsKey(ImageAspect.ASPECT_ID))
            {
                mediaType = FanArtConstants.FanArtMediaType.Image;
            }

            FanArtImageSource fanArtImageSource = new FanArtImageSource
            {
                FanArtMediaType = mediaType,
                FanArtType      = FanArtConstants.FanArtType.Thumbnail,
                MaxWidth        = MAX_SIZE_THUMBS,
                MaxHeight       = MAX_SIZE_THUMBS,
                // Order matters here: if all arguments are complete, download will start. We control the start time by setting FanArtName after all required properties are set
                FanArtName = mediaItem.MediaItemId.ToString()
            };

            return(fanArtImageSource);
        }
Example #2
0
    public static ImageSource CreateFanArtImageSource(object source, int width, int height)
    {
      MediaItem mediaItem = source as MediaItem;
      if (mediaItem == null)
        return null;
      // Use the ThumbnailAspect as fallback for non-ML imported MediaItems
      if (mediaItem.MediaItemId == Guid.Empty)
        return ImageSourceFactory.CreateMediaItemThumbnailAspectSource(source, width, height);

      FanArtConstants.FanArtMediaType mediaType = FanArtConstants.FanArtMediaType.Undefined;
      // Special handling for ImageThumbs that might require rotation
      if (mediaItem.Aspects.ContainsKey(ImageAspect.ASPECT_ID))
        mediaType = FanArtConstants.FanArtMediaType.Image;

      FanArtImageSource fanArtImageSource = new FanArtImageSource
      {
        FanArtMediaType = mediaType,
        FanArtType = FanArtConstants.FanArtType.Thumbnail,
        MaxWidth = MAX_SIZE_THUMBS,
        MaxHeight = MAX_SIZE_THUMBS,
        // Order matters here: if all arguments are complete, download will start. We control the start time by setting FanArtName after all required properties are set
        FanArtName = mediaItem.MediaItemId.ToString()
      };
      return fanArtImageSource;
    }
        public override bool Convert(object val, Type targetType, object parameter, CultureInfo culture, out object result)
        {
            result = null;
            FanArtImageSource imageSource = val as FanArtImageSource;

            if (imageSource == null)
            {
                ImageSource source = val as ImageSource;
                if (source != null)
                {
                    result = source;
                    return(true);
                }
                return(false);
            }

            string param = parameter as string;

            if (string.IsNullOrEmpty(param))
            {
                return(false);
            }

            var args = param.Split(';');

            if (args.Length < 3)
            {
                return(false);
            }

            string fanartType = args[0];
            int    maxWidth;
            int    maxHeight;

            int.TryParse(args[1], out maxWidth);
            int.TryParse(args[2], out maxHeight);

            bool useCache = true;

            if (args.Length == 4 && !bool.TryParse(args[3], out useCache))
            {
                useCache = true;
            }

            result = new FanArtImageSource
            {
                FanArtMediaType = imageSource.FanArtMediaType,
                FanArtName      = imageSource.FanArtName,
                FanArtType      = fanartType,
                MaxWidth        = maxWidth,
                MaxHeight       = maxHeight,
                Cache           = useCache
            };

            return(true);
        }
        public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager)
        {
            Detach();
            base.DeepCopy(source, copyManager);
            FanArtImageSource fanArtImageSource = (FanArtImageSource)source;

            FanArtType      = fanArtImageSource.FanArtType;
            FanArtMediaType = fanArtImageSource.FanArtMediaType;
            FanArtName      = fanArtImageSource.FanArtName;
            MaxWidth        = fanArtImageSource.MaxWidth;
            MaxHeight       = fanArtImageSource.MaxHeight;
            Attach();
        }
    public override bool Convert(object val, Type targetType, object parameter, CultureInfo culture, out object result)
    {
      result = null;
      FanArtImageSource imageSource = val as FanArtImageSource;
      if (imageSource == null)
      {
        ImageSource source = val as ImageSource;
        if (source != null)
        {
          result = source;
          return true;
        }
        return false;
      }

      string param = parameter as string;
      if (string.IsNullOrEmpty(param))
        return false;

      var args = param.Split(';');
      if (args.Length < 3)
        return false;

      FanArtConstants.FanArtType fanartType;
      if (!Enum.TryParse(args[0], out fanartType))
        return false;

      int maxWidth;
      int maxHeight;
      int.TryParse(args[1], out maxWidth);
      int.TryParse(args[2], out maxHeight);

      bool useCache = true;
      if (args.Length == 4 && !bool.TryParse(args[3], out useCache))
        useCache = true;

      result = new FanArtImageSource
        {
          FanArtMediaType = imageSource.FanArtMediaType,
          FanArtName = imageSource.FanArtName,
          FanArtType = fanartType,
          MaxWidth = maxWidth,
          MaxHeight = maxHeight,
          Cache = useCache
        };

      return true;
    }
Example #6
0
        public static ImageSource CreateFanArtImageSource(object source, int width, int height)
        {
            MediaItem mediaItem = source as MediaItem;

            if (mediaItem == null)
            {
                return(null);
            }
            // Use the ThumbnailAspect as fallback for non-ML imported MediaItems
            if (mediaItem.MediaItemId == Guid.Empty)
            {
                return(ImageSourceFactory.CreateMediaItemThumbnailAspectSource(source, width, height));
            }

            string mediaType = FanArtMediaTypes.Undefined;

            if (FanArtMediaTypes.TryGetMediaItemFanArtType(mediaItem, out var detectedType))
            {
                mediaType = detectedType;
            }
            // Special handling for ImageThumbs that might require rotation
            if (mediaItem.Aspects.ContainsKey(ImageAspect.ASPECT_ID))
            {
                mediaType = FanArtMediaTypes.Image;
            }

            FanArtImageSource fanArtImageSource = new FanArtImageSource
            {
                FanArtMediaType = mediaType,
                FanArtType      = FanArtTypes.Thumbnail,
                MaxWidth        = MAX_SIZE_THUMBS,
                MaxHeight       = MAX_SIZE_THUMBS,
                // Order matters here: if all arguments are complete, download will start. We control the start time by setting FanArtName after all required properties are set
                FanArtName = mediaItem.MediaItemId.ToString()
            };

            return(fanArtImageSource);
        }