2013-07-14 25 views
0

如何加快音頻文件從iphone到iPhone上的下載速度。點擊播放按鈕和播放開始之間有很長的等待時間。 (我只是播放文件沒有下載)加速音樂文件的播放,iPhone中的SoundCloud

什麼是最好的解決方案使用?可以下載異步,使其更快? 我正在使用JSON來獲取數據和AVAudioPlayer播放聲音。 任何建議將有助於

感謝

回答

0

我用音頻流光類集成到我的項目和

0

我已經找到一個很好的答案在這裏,以加快使用AVPlayer播放它的作品非常好。

Soundcloud iOS API - playing sound from link

我已經嘗試過的反應真的很好!

的代碼是:

NSString *trackID = @"100026228"; 
NSString *clientID = @"YOUR_CLIENT_ID"; 
NSURL *trackURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.soundcloud.com/tracks/%@/stream?client_id=%@", trackID, clientID]]; 

NSURLSessionTask *task = [[NSURLSession sharedSession] dataTaskWithURL:trackURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 
    // self.player is strong property 
    self.player = [[AVAudioPlayer alloc] initWithData:data error:nil]; 
    [self.player play]; 
}]; 

[task resume];