Esempio n. 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var            cache  = HNKCache.SharedCache;
            HNKCacheFormat format = (HNKCacheFormat)cache.Formats["thumbnail"];

            if (format == null)
            {
                format = new HNKCacheFormat("thumbnail")
                {
                    Size               = new SizeF(320, 240),
                    ScaleMode          = HNKScaleMode.AspectFill,
                    CompressionQuality = 0.5f,
                    DiskCapacity       = 1 * 1024 * 1024,
                    PreloadPolicy      = HNKPreloadPolicy.LastSession
                };
            }

            var fetcher = new HNKNetworkFetcher(new NSUrl("https://media-cdn.tripadvisor.com/media/photo-s/03/9b/30/26/seattle.jpg"));

            fetcher.FetchImage((imag) => { HanekeImageView.Image = imag; }, (err) => { });
            HanekeImageView.SetCacheFormat(format);
            //HanekeImageView.SetImage(new NSUrl("https://www.xamarin.com/content/images/pages/branding/assets/xamagon.png"), UIImage.FromBundle("41015.png") );
            HanekeButton.SetBackgroundImage(new NSUrl("https://www.xamarin.com/content/images/pages/branding/assets/xamagon.png"), UIControlState.Normal, UIImage.FromBundle("41015.png"));
        }
Esempio n. 2
0
        async void FetchArtwork(Song song)
        {
            try
            {
                var art = await song.GetLocalImage(Images.MaxScreenSize);

                if (art == null)
                {
                    var url = await ArtworkManager.Shared.GetArtwork(song);

                    if (string.IsNullOrWhiteSpace(url))
                    {
                        return;
                    }
                    TaskCompletionSource <UIImage> tcs = new TaskCompletionSource <UIImage>();
                    var fether = new HNKNetworkFetcher(new NSUrl(url));
                    fether.FetchImage((image) => { tcs.TrySetResult(image); },
                                      (error) => { tcs.TrySetException(new Exception(error.ToString())); });
                    art = await tcs.Task;
                    if (art == null || song.Id != Settings.CurrentSong)
                    {
                        return;
                    }
                }
                artwork = new MPMediaItemArtwork(art);
                if (nowPlayingInfo == null)
                {
                    return;
                }
                nowPlayingInfo.Artwork = artwork;
                App.RunOnMainThread(() => MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = nowPlayingInfo);
            }
            catch (Exception ex)
            {
                LogManager.Shared.Report(ex);
            }
        }