~ubuntuone-ios-client-team/ubuntuone-ios-contacts/trunk

« back to all changes in this revision

Viewing changes to musicstreaming/controls/AsynchronousImageView.m

  • Committer: Jason Foreman
  • Date: 2011-06-16 18:33:42 UTC
  • mfrom: (191.1.60 master)
  • Revision ID: jason.foreman@canonical.com-20110616183342-vl7a4804xsf0s1b5
Merging branches for v 2.0.

lp:~threeve/ubuntuone-ios-client/master
lp:~urbanape/ubuntuone-ios-client/downloader

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
//  AsynchronousImageView.m
3
 
//  GLOSS
4
 
//
5
 
//  Created by Слава on 22.10.09.
6
 
//  Copyright 2009 Slava Bushtruk. All rights reserved.
7
 
//  ---------------------------------------------------
8
 
//
9
 
//  Modified by Ben Baron for the iSub project.
10
 
//
11
 
 
12
 
#import "AsynchronousImageView.h"
13
 
#import "iSubAppDelegate.h"
14
 
#import "StreamingPlayer.h"
15
 
 
16
 
@implementation AsynchronousImageView
17
 
 
18
 
- (void)loadImageFromURLString:(NSString *)theUrlString
19
 
{
20
 
        [self.image release], self.image = nil;
21
 
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:theUrlString]
22
 
                                             cachePolicy:NSURLRequestReturnCacheDataElseLoad
23
 
                                         timeoutInterval:30.0];
24
 
        
25
 
        connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
26
 
}
27
 
 
28
 
 
29
 
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData 
30
 
{
31
 
    if (data == nil)
32
 
        data = [[NSMutableData alloc] initWithCapacity:2048];
33
 
        
34
 
    [data appendData:incrementalData];
35
 
}
36
 
 
37
 
 
38
 
- (void)connection:(NSURLConnection *)theConnection didFailWithError:(NSError *)error
39
 
{
40
 
        NSLog(@"Connection to album art failed");
41
 
        
42
 
        [[StreamingPlayer sharedStreamingPlayer] setCurrentCoverArt:[UIImage imageNamed:@"default-album-art.png"]];
43
 
        self.image = [StreamingPlayer sharedStreamingPlayer].currentCoverArt;
44
 
        
45
 
        RELEASE_SAFELY(data);
46
 
        RELEASE_SAFELY(connection);
47
 
}       
48
 
 
49
 
        
50
 
- (void)connectionDidFinishLoading:(NSURLConnection *)theConnection 
51
 
{
52
 
        UIImage *image = [UIImage imageWithData:data];
53
 
        
54
 
        if (image)
55
 
        {
56
 
                [StreamingPlayer sharedStreamingPlayer].currentCoverArt = image;
57
 
        }
58
 
        else 
59
 
        {
60
 
                [StreamingPlayer sharedStreamingPlayer].currentCoverArt = [UIImage imageNamed:@"default-album-art.png"];
61
 
        }
62
 
        
63
 
        self.image = [StreamingPlayer sharedStreamingPlayer].currentCoverArt;
64
 
        
65
 
        RELEASE_SAFELY(data);
66
 
        RELEASE_SAFELY(connection);
67
 
}
68
 
 
69
 
 
70
 
- (void)dealloc
71
 
{
72
 
        RELEASE_SAFELY(data);
73
 
        RELEASE_SAFELY(connection);
74
 
 
75
 
    [super dealloc];
76
 
}
77
 
 
78
 
@end