Get album art to update from URL every time song changes or every few seconds using Stormy Productions RadioKit

StackOverflow https://stackoverflow.com/questions/14863397

Question

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!

Was it helpful?

Solution

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;
    });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top