在IOS应用程序中播放SoundCloud文件 [英] Playing a SoundCloud file in IOS app
问题描述
使用提供的快速入门指南想在IOS应用程序中播放SoundCloud轨道。
Using the quick start guide provided would like to play a SoundCloud track within IOS app.
播放流的代码如下:
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 - 但是,如果新用户之前可以收听多个曲目,那么可用性是有用的。
Problem: is there a method to play a SoundCloud file without logging in to your SoundCloud account first? We hope all users consider using SoundCloud - however for usability if would be useful if new users could listen to a number of tracks before.
推荐答案
对于使用IOS Soundcloud SDK的公共访问,您需要将Soundcloud clientID作为参数添加到您的请求字符串中:
For public access with the IOS Soundcloud SDK you will need to add the Soundcloud clientID as a parameter to your request string:
NSString *urlString = [NSString stringWithFormat:@"%@?client_id=%@", publicTrackUrlString, yourSCClientID];
[SCRequest performMethod: SCRequestMethodGET
onResource: [NSURL URLWithString:urlString]
usingParameters: nil
withAccount: nil
sendingProgressHandler: nil
responseHandler:^(NSURLResponse *response, NSData *data, NSError *error){
//
}];
当withAccount:参数为nil时,它将适用于公共曲目。
Then it will work for public tracks when the withAccount: parameter is nil.
更优雅的是,你可以将client_id包装在字典中并与usingParameters一起使用:
More elegantly, you can as well pack the "client_id" in a dictionary and use it with usingParameters:
NSDictionary * params = @ {@client_id:yourSCClientID};
这篇关于在IOS应用程序中播放SoundCloud文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!