Soundcloud iOS API - playing sound from link

后端 未结 1 909
北荒
北荒 2021-02-06 14:04

I want to play a public sound in my app using the Soundcloud API. After some searchs around the web, I find a way to do it, but I can\'t make my code works. Here\'s the code I t

相关标签:
1条回答
  • 2021-02-06 14:29
    NSString *trackID = @"100026228";
    NSString *clientID = @"YOUR_CLIENT_ID";
    NSURL *trackURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.soundcloud.com/tracks/%@/stream?client_id=%@", trackID, clientID]];
    
    NSURLSessionTask *task = [[NSURLSession sharedSession] dataTaskWithURL:trackURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        // self.player is strong property
        self.player = [[AVAudioPlayer alloc] initWithData:data error:nil];
        [self.player play];
    }];
    
    [task resume];
    

    You can get the track ID from the resolve resource: http://api.soundcloud.com/resolve.json?url=http://soundcloud.com/miroslav-osipovic/the-cat-empire-the-lost-song&client_id=YOUR_CLIENT_ID.

    0 讨论(0)
提交回复
热议问题