Using the quick start guide provided would like to play a SoundCloud track within IOS app.
The code provided to play 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 method to play a SoundCloud file without logging in to your SoundCloud account first? We hope all users consider using SoundCloud - however for usability if would be useful if new users could listen to a number of tracks before.
For public access with the IOS Soundcloud SDK you will need to add the Soundcloud clientID as a parameter to your request 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){
//
}];
Then it will work for public tracks when the withAccount: parameter is nil.
More elegantly, you can as well pack the "client_id" in a dictionary and use it with usingParameters:
NSDictionary *params = @{@"client_id": yourSCClientID} ;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.