private static Task <ImageSource> GetImageAsync(string artist) { var tcs = new TaskCompletionSource <ImageSource>(); Application.Current.Dispatcher.Invoke(async() => { var cachedImage = await CacheService.GetCachedImage("artists/" + CacheService.GetSafeFileName(artist + "_big.jpg")); if (cachedImage != null) { tcs.SetResult(cachedImage); return; } var imageUri = await DataService.GetArtistImage(artist, true); if (imageUri != null) { cachedImage = await CacheService.CacheImage(imageUri.OriginalString, "artists/" + CacheService.GetSafeFileName(artist + "_big.jpg")); tcs.SetResult(cachedImage); } tcs.SetResult(null); }); return(tcs.Task); }
private async void GetArtistImage() { if (Artist == null) { return; } try { var cachedImage = await CacheService.GetCachedImage("artists/" + CacheService.GetSafeFileName(Artist.Name + "_big.jpg")); if (cachedImage != null) { ArtistImage = cachedImage; return; } var imageUri = await DataService.GetArtistImage(Artist.Name, true); if (imageUri != null) { cachedImage = await CacheService.CacheImage(imageUri.OriginalString, "artists/" + CacheService.GetSafeFileName(Artist.Name + "_big.jpg")); ArtistImage = cachedImage; return; } ArtistImage = null; } catch (Exception ex) { LoggingService.Log(ex); } }
private async void GetArtistImage(CancellationToken token) { if (CurrentAudio == null) { return; } if (CurrentAudio.Artist == _lastArtist) { return; } _lastArtist = CurrentAudio.Artist; string imageType = Settings.Instance.ShowBackgroundArt ? "big" : "medium"; try { var cachedImage = await CacheService.GetCachedImage("artists/" + CacheService.GetSafeFileName(CurrentAudio.Artist + "_" + imageType + ".jpg")); if (cachedImage != null) { ArtistImage = cachedImage; return; } if (Settings.Instance.DownloadArtistArt) { var imageUri = await DataService.GetArtistImage(CurrentAudio.Artist, Settings.Instance.ShowBackgroundArt); if (imageUri != null) { if (token.IsCancellationRequested) { return; } cachedImage = await CacheService.CacheImage(imageUri.OriginalString, "artists/" + CacheService.GetSafeFileName(CurrentAudio.Artist + "_" + imageType + ".jpg")); if (token.IsCancellationRequested) { return; } ArtistImage = cachedImage; return; } } ArtistImage = null; } catch (Exception ex) { LoggingService.Log(ex); } }
private async void GetArtistImage(CancellationToken token) { var audio = AudioService.CurrentAudio; if (audio == null) { return; } if (audio.Artist == _lastArtist) { return; } _lastArtist = audio.Artist; string imageType = "big"; try { var cachedImage = await CacheService.GetCachedImage("artists/" + CacheService.GetSafeFileName(audio.Artist + "_" + imageType + ".jpg")); if (cachedImage != null) { var lastUpdateTime = FileStorage.GetFileUpdateTime("artists/" + CacheService.GetSafeFileName(audio.Artist + "_" + imageType + ".jpg")); if ((DateTime.Now - lastUpdateTime).TotalDays < 14) { //if image was downloaded less than 2 weeks ago, show it, else download newer ArtistImage = cachedImage; return; } } if (Settings.Instance.DownloadArtistArt) { var imageUri = await DataService.GetArtistImage(audio.Artist, true); if (imageUri != null) { if (token.IsCancellationRequested) { return; } cachedImage = await CacheService.CacheImage(imageUri.OriginalString, "artists/" + CacheService.GetSafeFileName(audio.Artist + "_" + imageType + ".jpg")); if (token.IsCancellationRequested) { return; } ArtistImage = cachedImage; return; } } ArtistImage = null; } catch (Exception ex) { LoggingService.Log(ex); } }