Start playing SoundCloud audio stream on iOS using pre-buffer

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];
         }];
}  
+5
source share
2 answers

To transfer tracks from SoundCloud, all you have to do is transfer the AVPlayer URL with the client ID:

   NSString *urlString = [NSString stringWithFormat:@"%@?client_id=%@", track.streamURL, self.clientId];
player = [[AVPlayer alloc] initWithURL:[NSURL URLWithString:urlString]];
[player play];

. , .

+3

afaik . SoundCloud API, Pull .

, , CocoaSoundCloudAPI OAuth2Client.

!

+1

All Articles