Objective c 如何实现字符串SCAudioStream?-声云

Objective c 如何实现字符串SCAudioStream?-声云,objective-c,audio,cloud,audio-streaming,Objective C,Audio,Cloud,Audio Streaming,我正在使用sound cloud sdk,我正在尝试使用它们的库来播放音频流 我还没有找到任何关于如何使用该类的参考资料 如果您能提供任何帮助,我将不胜感激。如果您正在谈论我可以帮助您 首先,您应该运行此方法以通过其ID获取有关轨迹的一些信息: [api performMethod: @"GET" onResource: @"tracks" withParameters: [NSDictionary dictionaryWithObject:track

我正在使用sound cloud sdk,我正在尝试使用它们的库来播放音频流

我还没有找到任何关于如何使用该类的参考资料

如果您能提供任何帮助,我将不胜感激。

如果您正在谈论我可以帮助您

首先,您应该运行此方法以通过其ID获取有关轨迹的一些信息:

[api performMethod: @"GET" 
            onResource: @"tracks" 
        withParameters: [NSDictionary dictionaryWithObject:trackID forKey:@"ids"] 
               context: @"trackid" 
              userInfo: nil];
如果您不知道trackID,并且只有指向以下轨迹的链接:,请运行此方法:

[api performMethod: @"GET" 
            onResource: @"resolve" 
        withParameters: [NSDictionary dictionaryWithObject:songLink forKey:@"url"]
               context: @"songname" 
              userInfo: nil];
然后您应该实现委托的方法:

- (void)soundCloudAPI:(SCSoundCloudAPI *)soundCloudAPI 
    didFinishWithData:(NSData *)data 
              context:(id)context 
             userInfo:(id)userInfo;

- (void)soundCloudAPI:(SCSoundCloudAPI *)soundCloudAPI 
     didFailWithError:(NSError *)error 
              context:(id)context 
             userInfo:(id)userInfo;
在第一种方法中,您应该使用JSON解析器JSONKit或SBJSON解析数据。你应该去查字典

streamURL = [(NSDictionary *)jsonData objectForKey:@"stream_url"];
streamable = [[(NSDictionary *)jsonData objectForKey:@"streamable"] boolValue];
如果此轨迹可流化,则可以通过以下方式获得SCAudioStream:

stream = [[SCAudioStream alloc] initWithURL:[NSURL URLWithString:streamURL] authentication:auth];
conf = [SCSoundCloudAPIConfiguration configurationForProductionWithClientID: kSCClientID
                                                                       clientSecret: kSCClientSecret
                                                                        redirectURL: kSCRedirectURL];
auth = [[SCSoundCloudAPIAuthentication alloc] initWithAuthenticationDelegate:self apiConfiguration:conf];
您可以通过以下方式在init方法的前面创建身份验证:

stream = [[SCAudioStream alloc] initWithURL:[NSURL URLWithString:streamURL] authentication:auth];
conf = [SCSoundCloudAPIConfiguration configurationForProductionWithClientID: kSCClientID
                                                                       clientSecret: kSCClientSecret
                                                                        redirectURL: kSCRedirectURL];
auth = [[SCSoundCloudAPIAuthentication alloc] initWithAuthenticationDelegate:self apiConfiguration:conf];
现在你有了斯库迪奥斯特团队

//Playing
[stream play];

//Pause
[srteam pause];

//Seeking
[stream seekToMillisecond:ms startPlaying:YES];
仅此而已: