2013-03-21 39 views
6

使用所提供的快速入门指南可以在IOS应用程序中播放SoundCloud音轨。在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,但如果新用户以前可以听很多曲目,那么这对于可用性来说很有用。

+0

你试过省略负责账户的初始化代码?你有特别的问题吗? – 2013-03-21 09:02:44

+1

是的尝试设置帐户:无,没有工作,因此假设您需要登录到SoundCloud播放音频。 – Magnus 2013-03-21 15:00:31

+0

马格努斯,我知道这是迟到,但我有同样的问题...你找到一个解决方法? – gg13 2013-04-04 02:50:03

回答

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:参数是零。

更优雅,你可以也包在字典中的“CLIENT_ID”,并与usingParameters使用它:

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

+1

你可以标记我的答案是正确的。谢谢 – 2013-05-01 13:21:46

+0

这对我有效。完美的答案。 – 2014-02-26 17:34:48

+0

@ sn-gerzonic'NSOSStatusErrorDomain Code = 1954115647“操作无法完成(OSStatus错误1954115647.)'我得到这个错误请给我解决方案 – 2016-07-26 05:06:16

相关问题