gpt4 book ai didi

ios - 不播放来自 stream_url ing SoundCloud API 的声音

转载 作者:可可西里 更新时间:2023-11-01 03:35:09 25 4
gpt4 key购买 nike

我可以在表格 View 中显示歌曲,但我无法播放。

这是我点击获取轨道按钮时的代码

- (IBAction) getTracks:(id) sender
{

SCRequestResponseHandler handler;
handler = ^(NSURLResponse *response, NSData *data, NSError *error) {
NSError *jsonError = nil;
NSJSONSerialization *jsonResponse = [NSJSONSerialization
JSONObjectWithData:data
options:0
error:&jsonError];
if (!jsonError && [jsonResponse isKindOfClass:[NSArray class]]) {
SCTTrackListViewController *trackListVC;
trackListVC = [[SCTTrackListViewController alloc]
initWithNibName:@"SCTTrackListViewController"
bundle:nil];
trackListVC.tracks = (NSArray *)jsonResponse;
NSLog(@"json %@",(NSArray *)jsonResponse);
[self presentViewController:trackListVC
animated:YES completion:nil];
}
};



NSString *resourceURL = @"https://api.soundcloud.com/users/54237635/tracks.json?client_id=8a58d84d48322f5661cf14a3d80e005d";


[SCRequest performMethod:SCRequestMethodGET
onResource:[NSURL URLWithString:resourceURL]
usingParameters:nil
withAccount:nil
sendingProgressHandler:nil
responseHandler:handler];
}

这是我在 tableview 中的 didselect 中的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

NSDictionary *track = [self.tracks objectAtIndex:indexPath.row];
NSString *streamURL = [track objectForKey:@"stream_url"];


[SCRequest performMethod:SCRequestMethodGET
onResource:[NSURL URLWithString:streamURL]
usingParameters:nil
withAccount:nil
sendingProgressHandler:nil
responseHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSError *playerError;
player = [[AVAudioPlayer alloc] initWithData:data error:&playerError];
[player prepareToPlay];
[player play];
}];

NSLog(@"streamURL %@", [track objectForKey:@"stream_url"]);
}

最佳答案

由 OP 解决:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)
{

NSDictionary *track = [self.tracks objectAtIndex:indexPath.row];
NSString *streamURL = [track objectForKey:@"stream_url"];

NSString *urlString = [NSString stringWithFormat:@"%@?client_id=%@", streamURL,CLIENT_ID];//Your client ID


[SCRequest performMethod:SCRequestMethodGET
onResource:[NSURL URLWithString:urlString]
usingParameters:nil
withAccount:nil
sendingProgressHandler:nil
responseHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSError *playerError;

NSLog(@"data:%@",data);
player = [[AVAudioPlayer alloc] initWithData:data error:&playerError];
[player prepareToPlay];
[player play];
}];
}

关于ios - 不播放来自 stream_url ing SoundCloud API 的声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18245805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com