2013-03-21 38 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

相關問題