使用预缓冲开始在iOS中播放SoundCloud音频流

使用预缓冲开始在iOS中播放SoundCloud音频流,第1张

概述使用SoundCloud Developers页面中的以下代码示例,AVAudioPlayer将在收到SCRequest响应后开始播放.根据所请求文件的大小,这可能需要一些时间.iOS SoundCloud API是否提供预缓冲解决方案,以便可以在收到所有数据之前开始播放音频,或者我是否需要实现在NSURLConnection的帮助下自己的解决方案,以实现这一目标? - (void)tableVi 使用SoundCloud Developers页面中的以下代码示例,AVAudioPlayer将在收到SCRequest响应后开始播放.根据所请求文件的大小,这可能需要一些时间.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];

它需要一些额外的工作才能使其成为渐进式下载.希望有所帮助.

总结

以上是内存溢出为你收集整理的使用预缓冲开始在iOS中播放SoundCloud音频流全部内容,希望文章能够帮你解决使用预缓冲开始在iOS中播放SoundCloud音频流所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1068877.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存