6

使用提供的快速入门指南想在 IOS 应用程序中播放 SoundCloud 曲目。

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

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

问题:有没有一种无需先登录 SoundCloud 帐户即可播放 SoundCloud 文件的方法?我们希望所有用户都考虑使用 SoundCloud - 但是,如果新用户之前可以收听许多曲目,那么出于可用性考虑,这将很有用。

4

1 回答 1

14

对于 IOS Soundcloud SDK 的公共访问,您需要将 Soundcloud clientID 作为参数添加到您的请求字符串中:

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: 参数为 nil 时,它将适用于公共轨道。

更优雅的是,您还可以将“client_id”打包到字典中并与 usingParameters 一起使用:

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

于 2013-03-25T16:53:53.183 回答