我在我的应用程序中集成了 soundCloud api。我正在使用 api 文档中提到的以下代码播放 soundCloud 歌曲。
NSString *urlString = [NSString stringWithFormat:@"%@?client_id=%@",actiVityObj.songUrl, @"e0b860d9584b7194183a9e797dc0fc16"];
[SCRequest performMethod:SCRequestMethodGET
onResource:[NSURL URLWithString:urlString]
usingParameters:nil
withAccount:nil
sendingProgressHandler:nil
responseHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSError *playerError;
audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:&playerError];
audioPlayer.numberOfLoops = 0;
audioPlayer.volume = 1.0f;
audioPlayer.delegate = self;
[audioPlayer prepareToPlay];
if (audioPlayer == nil)
{
}
else
{
[audioPlayer play];
}
}];
但问题是播放歌曲需要花费太多时间,这太荒谬了。搜索后我发现它先下载轨道然后播放。有没有办法一步一步地流式传输。任何帮助将不胜感激。谢谢。
最佳答案
你应该使用 AVPlayer如果您想流式传输音频。
关于ios - SoundCloud 轨道在 iPhone 中播放时间过长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19444231/