Create a page that displays the playlist in JSON, and then in xcode create a class that loads JSON for track dictionaries and plays the downloaded content using AVPlayer (or AVQueuePlayer if you play the entire list).
Here is some abstract code:
playlistDownloader.m - (void)downloadPlaylist{ dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_sync(concurrentQueue, ^{ NSURL *url = [NSURL URLWithString:@"http://www.yourwebsite.com/playlist.json?id=1"]; NSData *data = [NSData dataWithContentsOfURL:url]; NSError *error; id trackData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; if (!error) { tempTrackArray = trackData; } else { NSLog(@"Playlist wasn't able to download"); } }); }
tempTrackArray will be the declaration declared in the class.
Then in your player you will do something like this:
audioPlayer.m - (void)instanciateAudioPlayer { NSDictionary *trackDictionary = [playListDownloader.tempTrackArray objectAtIndex:0]; NSString *urlString = [trackDictionary objectForKey:@"stream_url"]; AVAsset *asset = [AVAsset assetWithURL:streamURL]; AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset]; [avPlayer initWithPlayerItem:playerItem]; }
This is some really crude code, but its general meaning is what you are trying to do. Should make you go in the right direction.
source share