Using the following code sample on the SoundCloud developers page, AVAudioPlayer will start playback after receiving a SCRequest response. Depending on the size of the requested file, this may take some time.
Does the SoundCloud iOS API offer a pre-installation solution so that I can start playing audio before all the data has been received, or do I need to implement my own solution using NSURLConnection to achieve this?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *track = [self.tracks objectAtIndex:indexPath.row];
NSString *streamURL = [track objectForKey:@"stream_url"];
SCAccount *account = [SCSoundCloud account];
[SCRequest performMethod:SCRequestMethodGET
onResource:[NSURL URLWithString:streamURL]
usingParameters:nil
withAccount:account
sendingProgressHandler:nil
responseHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSError *playerError;
player = [[AVAudioPlayer alloc] initWithData:data error:&playerError];
[player prepareToPlay];
[player play];
}];
}
source
share