我想将我的音频从SoundCloud帐户下载到我的IOS应用程序。 soundcloud API(download_url)中有一个属性,允许我下载并在浏览器中加载文件链接,但它在iPhone / iPad中无法正常工作。
这里的任何人都可以帮我找到一种方法从soundcloud下载音频到我的iPhone应用程序吗?
另外,我尝试使用NSData保存文件并重新读取并再次播放但我无法确定下载是否发生或保存?我没有任何迹象表明下载过程正在运行。
有关下载和保存要在离线模式下播放的文件的想法吗?
答案 0 :(得分:0)
SoundCloud拥有漂亮的ios Sdk SoundCloud docs。在所有你需要的文档中。无需重新发明轮子)))。
答案 1 :(得分:0)
有时您只需要阅读SDK本身。
您真正应该问的是如何正确拨打以下内容。试试这个。 我没有测试过这个。只是猜测。
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 *err) {
if (err == nil) {
if ([[NSFileManager defaultManager] fileExistsAtPath:localPath]) {
NSLog(@"Overwriting for import.");
BOOL success = [[NSFileManager defaultManager] removeItemAtPath:localPath error:nil];
if (success) {
NSLog(@"Overwrite successful!");
} else {
NSLog(@"Overwrite failed");
return;
}
}
BOOL success = [[NSFileManager defaultManager] createFileAtPath:localPath contents:data attributes:nil];
if (success) {
NSLog(@"download complete");
} else {
NSLog(@"failed to create a new file");
}
} else {
NSLog(@"Failed to download track.");
}
}];