2
// AsynchronousImageView.m
5
// Created by Слава on 22.10.09.
6
// Copyright 2009 Slava Bushtruk. All rights reserved.
7
// ---------------------------------------------------
9
// Modified by Ben Baron for the iSub project.
12
#import "AsynchronousImageView.h"
13
#import "iSubAppDelegate.h"
14
#import "StreamingPlayer.h"
16
@implementation AsynchronousImageView
18
- (void)loadImageFromURLString:(NSString *)theUrlString
20
[self.image release], self.image = nil;
21
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:theUrlString]
22
cachePolicy:NSURLRequestReturnCacheDataElseLoad
23
timeoutInterval:30.0];
25
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
29
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData
32
data = [[NSMutableData alloc] initWithCapacity:2048];
34
[data appendData:incrementalData];
38
- (void)connection:(NSURLConnection *)theConnection didFailWithError:(NSError *)error
40
NSLog(@"Connection to album art failed");
42
[[StreamingPlayer sharedStreamingPlayer] setCurrentCoverArt:[UIImage imageNamed:@"default-album-art.png"]];
43
self.image = [StreamingPlayer sharedStreamingPlayer].currentCoverArt;
46
RELEASE_SAFELY(connection);
50
- (void)connectionDidFinishLoading:(NSURLConnection *)theConnection
52
UIImage *image = [UIImage imageWithData:data];
56
[StreamingPlayer sharedStreamingPlayer].currentCoverArt = image;
60
[StreamingPlayer sharedStreamingPlayer].currentCoverArt = [UIImage imageNamed:@"default-album-art.png"];
63
self.image = [StreamingPlayer sharedStreamingPlayer].currentCoverArt;
66
RELEASE_SAFELY(connection);
73
RELEASE_SAFELY(connection);