void StartImageDownload(ListView listView, int position, IIconAndTitleItem audio)
        {
            if (_imageDownloadsInProgress.Contains(audio.Id))
            {
                return;
            }

            var url = new Uri(audio.IconUrl);

            if (_imageDownloader.HasLocallyCachedCopy(url))
            {
                var image = _imageDownloader.GetImage(url);
                FinishImageDownload(listView, position, audio, (Bitmap)image);
            }
            else
            {
                _imageDownloadsInProgress.Add(audio.Id);

                _imageDownloader.GetImageAsync(url).ContinueWith(t =>
                {
                    if (!t.IsFaulted)
                    {
                        FinishImageDownload(listView, position, audio, (Bitmap)t.Result);
                    }
                },
                                                                 TaskScheduler.FromCurrentSynchronizationContext()
                                                                 );
            }
        }
Beispiel #2
0
        public static async Task <List <Film> > PopulateMovieListAsync(IApiMovieRequest movieApi, ApiSearchResponse <MovieInfo> apiResponse)
        {
            List <Film> movies = new List <Film>();

            StorageClient   storageClient   = new StorageClient();
            ImageDownloader imageDownloader = new ImageDownloader(storageClient);

            foreach (MovieInfo info in apiResponse.Results)
            {
                ApiQueryResponse <MovieCredit> castResponse = await movieApi.GetCreditsAsync(info.Id);

                ApiQueryResponse <Movie> infoResponse = await movieApi.FindByIdAsync(info.Id);

                Film movie = new Film()
                {
                    Title       = info.Title,
                    ReleaseYear = infoResponse.Item.ReleaseDate.Year,
                    Runtime     = infoResponse.Item.Runtime.ToString(),
                    Genre       = new List <string>(),
                    Actors      = new List <string>(),
                    Description = infoResponse.Item.Overview,
                    PosterPath  = infoResponse.Item.PosterPath
                };

                if (infoResponse.Item.Genres.Count != 0)
                {
                    for (int i = 0; i < infoResponse.Item.Genres.Count; i++)
                    {
                        movie.Genre.Add(infoResponse.Item.Genres[i].Name);
                    }
                }

                if (castResponse.Item.CastMembers.Count != 0)
                {
                    for (int i = 0; i < castResponse.Item.CastMembers.Count && i < 3; i++)
                    {
                        movie.Actors.Add(castResponse.Item.CastMembers[i].Name);
                    }
                }
                movies.Add(movie);

                if (movie.PosterPath != null)
                {
                    await imageDownloader.GetImage(movies);
                }
            }
            return(movies);
        }
Beispiel #3
0
        public HttpResponseMessage Get(long id)
        {
            HttpResponseMessage result = new HttpResponseMessage(); //HttpStatusCode.OK

            try
            {
                result.StatusCode = HttpStatusCode.OK;
                result.Content    = new ByteArrayContent(ImageDownloader.GetImage(id, ImageSizeEnum.Thumbnail));
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
                return(result);
            }
            catch (Exception)
            {
                result.StatusCode = HttpStatusCode.NotFound;
                return(result);
            }
        }
Beispiel #4
0
        public async static Task <ArrayList> ParseSearchResultJSON(string json)
        {
            ArrayList resultList = new ArrayList();

            dynamic rootObject = JsonConvert.DeserializeObject(json);

            JArray items = rootObject.items;

            for (int i = 0; i < items.Count; i++)
            {
                VideoInfo currentResult = new VideoInfo();

                dynamic item = JsonConvert.DeserializeObject(items[i].ToString());

                string videoId    = item.id.videoId;
                string videoTitle = item.snippet.title;
                string author     = item.snippet.channelTitle;
                string youtubeURL = String.Format(Strings.youtubeFormatURL, item.id.videoId);
                string thumbURL   = item.snippet.thumbnails.medium.url;

                Log.D(Strings.Tags.JSON_UTILS, "===============================================================");
                Log.D(Strings.Tags.JSON_UTILS, "Video ID      : " + videoId);
                Log.D(Strings.Tags.JSON_UTILS, "Title         : " + videoTitle);
                Log.D(Strings.Tags.JSON_UTILS, "Author        : " + author);
                Log.D(Strings.Tags.JSON_UTILS, "YouTube URL   : " + youtubeURL);
                Log.D(Strings.Tags.JSON_UTILS, "Thumbnail URL : " + thumbURL);

                currentResult.youtubeID    = videoId;
                currentResult.title        = videoTitle;
                currentResult.author       = author;
                currentResult.youtubeURL   = youtubeURL;
                currentResult.thumbnailURL = thumbURL;

                Image thumbnailImage = await ImageDownloader.GetImage(thumbURL);

                currentResult.thumbnailImage = thumbnailImage;

                resultList.Add(currentResult);
            }

            return(resultList);
        }