簡體   English   中英

在IOS應用程序中播放SoundCloud文件

[英]Playing a SoundCloud file in IOS app

使用提供的快速入門指南想在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 - 但是,如果新用戶之前可以收聽多個曲目,那么可用性是有用的。

要使用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} ;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM