Sử dụng ví dụ mã sau từ trang Nhà phát triển SoundCloud, AVAudioPlayer sẽ bắt đầu phát sau khi nhận được phản hồi SCRequest. Tùy thuộc vào kích thước của tệp được yêu cầu, quá trình này có thể mất chút thời gian.
API SoundCloud của iOS có cung cấp giải pháp đệm trước để có thể bắt đầu phát âm thanh trước khi tất cả dữ liệu đã được nhận hay tôi cần triển khai giải pháp riêng với sự trợ giúp của NSURLConnection để đạt được điều này?Bắt đầu phát luồng âm thanh SoundCloud trong iOS bằng cách sử dụng bộ đệm trước
- (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];
}];
}
bạn có giải pháp cho vấn đề này không? –
bất kỳ giải pháp nào mà tôi cũng gặp phải trên cùng một vấn đề. –