簡體   English   中英

通過使用預緩沖區開始在iOS中播放SoundCloud音頻流

[英]Start playing SoundCloud audio stream in iOS by using a pre-buffer

使用SoundCloud開發人員頁面上的以下代碼示例,在收到SCRequest響應后,AVAudioPlayer將開始播放。 根據所請求文件的大小,這可能需要一些時間。

iOS SoundCloud API是否提供了預緩沖解決方案,以便可以在接收到所有數據之前開始播放音頻,或者我是否需要在NSURLConnection的幫助下實現自己的解決方案才能實現?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     NSDictionary *track = [self.tracks objectAtIndex:indexPath.row];
     NSString *streamURL = [track objectForKey:@"stream_url"];
     SCAccount *account = [SCSoundCloud account];

     [SCRequest performMethod:SCRequestMethodGET
                   onResource:[NSURL URLWithString:streamURL]
              usingParameters:nil
                  withAccount:account
       sendingProgressHandler:nil
              responseHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
             NSError *playerError;
             player = [[AVAudioPlayer alloc] initWithData:data error:&playerError];
             [player prepareToPlay];
             [player play];
         }];
}  

要從SoundCloud流式傳輸曲目,您所需要做的就是將URL傳遞給具有客戶端ID的AVPlayer:

   NSString *urlString = [NSString stringWithFormat:@"%@?client_id=%@", track.streamURL, self.clientId];
player = [[AVPlayer alloc] initWithURL:[NSURL URLWithString:urlString]];
[player play];

要逐步下載,將需要一些額外的工作。 希望能有所幫助。

afaik目前沒有預緩沖解決方案。 如果您想為我們的SoundCloud API做出貢獻,我們很樂意查看您關於此功能的請求請求。

這可能會影響CocoaSoundCloudAPIOAuth2Client

編碼愉快!

暫無
暫無

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

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