Play SoundCloud file in iOS app

Using the guide provided for quick launch, you want to play the SoundCloud track in your iOS app.

The code for playing the stream is here:

SCAccount *account = [SCSoundCloud account]; [SCRequest performMethod:SCRequestMethodGET onResource:[NSURL URLWithString:audioFile] usingParameters:nil withAccount:account sendingProgressHandler:nil responseHandler:^(NSURLResponse *response, NSData *data, NSError *error) { NSError *playerError; audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:&playerError]; audioPlayer.numberOfLoops = 0; [audioPlayer prepareToPlay]; [audioPlayer play]; }]; 

Problem: Is there a way to play a SoundCloud file without logging into your SoundCloud account? We hope that all users will consider using SoundCloud - however, for ease of use, if it would be useful if new users could listen to several tracks earlier.

+6
source share
1 answer

For open access using the iOS Soundcloud SDK, you need to add the Soundcloud client ID as a parameter to the query string:

 NSString *urlString = [NSString stringWithFormat:@"%@?client_id=%@", publicTrackUrlString, yourSCClientID]; [SCRequest performMethod: SCRequestMethodGET onResource: [NSURL URLWithString:urlString] usingParameters: nil withAccount: nil sendingProgressHandler: nil responseHandler:^(NSURLResponse *response, NSData *data, NSError *error){ // }]; 

It will then work for publicly accessible tracks when the withAccount: parameter is zero.

More elegantly, you can also package "client_id" in the dictionary and use it with parameters:

NSDictionary *params = @{@"client_id": yourSCClientID} ;

+14
source

All Articles