在iOS应用程序中播放SoundCloud文件

提供的快速入门指南可以在IOS应用程序中播放SoundCloud轨道。

提供播放stream的代码在这里:

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]; }]; 

问题:是否有一种方法可以在不loginSoundCloud帐户的情况下播放SoundCloud文件? 我们希望所有的用户都考虑使用SoundCloud,但是如果新用户以前可以听很多音轨的话,这对用户来说是有用的。

对于使用IOS Soundcloud SDK的公共访问,您需要将Soundcloud clientID作为参数添加到请求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){ // }]; 

然后当withAccount:参数为零时,它将用于公共轨道。

更优雅的是,你也可以在一个字典中包装“client_id”,并使用usingParameters:

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