Reputation: 120
I am getting music URL from my API and its duration is 4-5 minutes.Whenever i am trying to convert that URL to data it is consuming lot of time.Is there is any method so that we can convert it fastly.
This is what i tried:
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void)
{
data1 = [NSData dataWithContentsOfURL:trackurl];
dispatch_async(dispatch_get_main_queue(), ^(void)
{
self.player = [[AVAudioPlayer alloc] initWithData:data1 error:nil
[self.player play];
});
});
Upvotes: 0
Views: 893
Reputation: 122401
Well you cannot do much to influence the speed of the internet connection, however perhaps you want to stream the audio rather than downloading it all before starting to play?
If so there is an alternative to AVAudioPlayer
here.
This might lead to similar issues if the download speed cannot keep up with play speed, but I think it's the only option.
Incidentally the way you phrase your question is very confusing. You are not converting a URL into data, you are downloading data using the location specified by a URL.
Upvotes: 2