简体   繁体   中英

speed up play of audio file , SoundCloud in iPhone

How can I speed up the download of audio file from sound cloud to my app in iphone. there is a long waiting time between the click play button and start of playing. (I just play the files no downloading )

what is the best solution to use ? can the download be asynchronies to make it faster ? I'm using JSON to get the data and AVAudioPlayer to play sound. any suggestions will be helpful

Thanks

我使用了集成到项目中的Audio Streamer类,并且效果很好

I have found a really good answer here to speed up the playing using AVPlayer.

Soundcloud iOS API - playing sound from link

I've tried already and the response is really good!

The code is:

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM