繁体   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