使用提供的快速入门指南想在
IOS应用程序中播放SoundCloud轨道.
提供播放流的代码如下:
SCAccount *account = [SCSoundCloud account]; [SCRequest performMethod:SCRequestMethodGET onResource:[NSURL URLWithString:audioFile] usingParameters:nil withAccount:account sendingProgressHandler:nil responseHandler:^(NSURLResponse *response,NSData *data,NSError *error) { NSError *playerError; audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:&playerError]; audioPlayer.numberOfLoops = 0; [audioPlayer prepareToPlay]; [audioPlayer play]; }];
问题:有没有一种方法可以播放SoundCloud文件而无需先登录到您的SoundCloud帐户?我们希望所有用户都考虑使用SoundCloud – 但是,如果新用户之前可以收听多个曲目,那么可用性是有用的.
解决方法
要使用IOS Soundcloud SDK进行公共访问,您需要将Soundcloud clientID作为参数添加到请求字符串中:
NSString *urlString = [NSString stringWithFormat:@"%@?client_id=%@",publicTrackUrlString,yourSCClientID]; [SCRequest performMethod: SCRequestMethodGET onResource: [NSURL URLWithString:urlString] usingParameters: nil withAccount: nil sendingProgressHandler: nil responseHandler:^(NSURLResponse *response,NSError *error){ // }];
然后,当withAccount:参数为nil时,它将适用于公共轨道.
更优雅的是,你可以将“client_id”打包在字典中并与usingParameters一起使用:
NSDictionary * params = @ {@“client_id”:yourSCClientID};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。