Last active
August 29, 2015 14:05
-
-
Save kioqq/840397d089297a7a7b5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)MetadataUpdate:(NSNotification*)notification | |
{ | |
if ([[[Player sharedManager] radioPlayer] timedMetadata]!=nil && [[[[Player sharedManager] radioPlayer] timedMetadata] count] > 0) { | |
_firstMeta = [[[[Player sharedManager] radioPlayer] timedMetadata] objectAtIndex:0]; | |
self.decodedString = [[NSString alloc] initWithData: [_firstMeta.value dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:YES] | |
encoding: NSUTF8StringEncoding]; | |
NSCharacterSet *charSet = [NSCharacterSet characterSetWithCharactersInString:@"-"]; | |
NSArray *stringArray = [self.decodedString componentsSeparatedByCharactersInSet:charSet]; | |
NSString *title = [stringArray objectAtIndex:0]; | |
NSString *artist = [stringArray lastObject]; | |
self.metaTrackName.text = _decodedString; | |
[[ItunesSearch sharedInstance] getTrackWithName:title artist:artist album:nil limitOrNil:@1 successHandler:^(NSArray *result) { | |
if ([result count] == 0) { | |
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init]; | |
[songInfo setObject:self.metaTrackName.text forKey:MPMediaItemPropertyTitle]; | |
[songInfo setObject:@"" forKey:MPMediaItemPropertyAlbumTitle]; | |
MPMediaItemArtwork *imageArt = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"placeholder"]]; | |
[songInfo setObject:imageArt forKey:MPMediaItemPropertyArtwork]; | |
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo]; | |
} | |
else | |
{ | |
NSDictionary *song = [result objectAtIndex:0]; | |
NSString *artworkURL = [song objectForKey:@"artworkUrl100"]; | |
NSString *bigArtworkURLString = [artworkURL stringByReplacingOccurrencesOfString:@"100x100-75" | |
withString:@"1200x1200-75"]; | |
NSURL *bigArtworkURL = [NSURL URLWithString:bigArtworkURLString]; | |
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:bigArtworkURL options:SDWebImageDownloaderUseNSURLCache progress:^(NSInteger receivedSize, NSInteger expectedSize) { | |
} completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { | |
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init]; | |
[songInfo setObject:self.metaTrackName.text forKey:MPMediaItemPropertyTitle]; | |
//[songInfo setObject:self.currentRadioStationString forKey:MPMediaItemPropertyArtist]; | |
[songInfo setObject:@"" forKey:MPMediaItemPropertyAlbumTitle]; | |
MPMediaItemArtwork *imageArt = [[MPMediaItemArtwork alloc] initWithImage:image]; | |
[songInfo setObject:imageArt forKey:MPMediaItemPropertyArtwork]; | |
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo]; | |
}]; | |
} | |
} failureHandler:^(NSError *error) { | |
NSLog(@"%@",error); | |
}]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment