2

To teach myself how to code in Objective-C, I'm creating an internet radio app for my Church. Here is the problem... I have album art that is uploading to my web server every time the song changes on the radio station. The album art always has the same name even if the actual pic changes. I bought code for the streaming part of my app so that is taken care of. To get an idea of how this code is implemented, you can download a demo implementation from the vendor's website. Unfortunately, I do not have a way to refresh the pic that is displayed in the app when the song changes. Below is some of the code for loading the album art (This is all in the viewDidLoad method).

UIImage *albumArt = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL    URLWithString:@"http://www.ourchurchwebserver.org/nameof.jpg"]]];
CGSize picSize = CGSizeMake(100, 100);
CGPoint picOrigin = CGPointMake(108, 74);
CGRect picFrame;
picFrame.size = picSize;
picFrame.origin = picOrigin;
ImageEnlarge * imEn =[[ImageEnlarge alloc]initWithFrame:picFrame];
[[imEn internal]setImage:albumArt];
[self.view addSubview:(imEn)];

What you see is the code used to provide for if a user taps the pic it will enlarge and if they tap it again it goes back to normal size. My first idea was to create an array and have is automatically rotate back and forth between the pictures (which have the same URL address) but my knowledge is too limited and research has proved futile!

Carl Veazey
  • 18,392
  • 8
  • 66
  • 81
  • Hi William, in general questions around here should focus most on the actual programming problem at hand, so there's no reason to apologize for being new :) I've edited your question to tone that down a bit, along with a couple of other small issues. If I misrepresented something, let me know. – Carl Veazey Feb 13 '13 at 22:35
  • As to your question's subject matter, is it a requirement to maintain the history of album artwork? Or can you just display whatever album artwork is currently on the server? – Carl Veazey Feb 13 '13 at 22:35
  • The pic that is on the server. The old album art is deleted from the server and replaced with a new one that has the same name but a different image...and thanks;) – Will Reeves Feb 13 '13 at 22:52
  • My confusion comes from your statement re: using an array to rotate back and forth between pictures. Is your requirement to do something with the old images on the client? Or do you just need to display the image as it stands on the server? – Carl Veazey Feb 13 '13 at 23:32
  • Well it was just an idea to use an array with the images file paths set to the url hoping if i put it on a loop it would the load the image every 4 seconds or whatever i set it to. Again just an idea. The point is to update the image to the new album art. The old album art is then no longer needed. So, yes just display the image as it stands on the server and update accordingly. – Will Reeves Feb 13 '13 at 23:37
  • Does the streaming portion of the app you purchased code for give any notifications or callbacks when the song changes? – Carl Veazey Feb 13 '13 at 23:56
  • That's the thing the code has the ability to update the title, artist, and album and it does update itself but the code that I bought uses a static library for part of the code so it is impossible to see half of the code. There is reference to album art lookup in the code using, if I remember correctly, MPMediaPlayerArtwork , or MPItemArtwork. It is a class that is built by Apple. I tried to contact the one I bought it from but he won't answer me. – Will Reeves Feb 14 '13 at 00:29
  • You can look at an exact copy of the actual code at – Will Reeves Feb 14 '13 at 00:47
  • Sorry meant to go to next line...http://stormyprods.com/Demos/RadioKitARC-4.5-Demo.zip – Will Reeves Feb 14 '13 at 00:49

1 Answers1

1

RadioKit.h defines a protocol StormysRadioKitDelegate that includes the method SRKMetaChanged. The demo project suggests using this method to kick off a request for the album artwork.

So you should add something like this to the implementation of this method. It dispatches a network download to a background thread and when it's done it updates the UI on the main thread.

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSData *albumArtImageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.ourchurchwebserver.org/nameof.jpg"]];
    dispatch_async(dispatch_get_main_queue(), ^{
        UIImage *albumArt = [UIImage imageWithData:albumArtImageData];
        self.imageEnlarge.internal.image = albumArt;
    });
});
Carl Veazey
  • 18,392
  • 8
  • 66
  • 81
  • Awesome! Wow I wish I would have asked earlier! Would have made my life so much easier! Your awesome! – Will Reeves Feb 14 '13 at 14:48
  • I do have another question that I am going to post about another issue with the code I bought. The help would be so much appreciated. – Will Reeves Feb 14 '13 at 14:53
  • The album art is loading fine but when I touch the image to enlarge three or four times it brings up a previous album art pic and leaves it enlarged while the current pic continues to get small and big in front of it. Is there some way to clear the previous album art from memory? – Will Reeves Feb 14 '13 at 16:05
  • @William It sounds like your `ImageEnlarge` class is creating another image view to use for `internal` and not removing the existing instance from its superview. Or you are creating another `ImageEnlarge` instance without cleaning up the old one. If you've added a view as a subview, its superview will keep a strong reference to it and it must be explicitly removed from the view hierarchy with the `removeFromSuperview` method. If that doesn't help you fix that issue, I'd suggest you create a self-contained example program to show the problem and post a new question. – Carl Veazey Feb 14 '13 at 16:27
  • When I run the ' removeFromSuperview ' method it does keep it from loading an old image but when the art is supposed to change it does not. What am I missing? ...and not sure how to create a self contained example program :\ – Will Reeves Feb 14 '13 at 17:00
  • @william hm, sounds like there may be more complexity with the resizing than I'd assume. I suggest a self contained progr for the strongest question but as long as you're able to construct a question clearly demonstrating your implementation of image resizing it may be straightforward to answer. – Carl Veazey Feb 15 '13 at 04:53
  • Got it. I'll post the implementation for the ImageEnlarge and the little bit for retrieving the album art. Hopefully we can find the contradictions. – Will Reeves Feb 15 '13 at 13:37
  • It is up. The question is titled Contradicting code causing multiple images. – Will Reeves Feb 15 '13 at 14:20