Quote:
Originally Posted by cristofercolmbos
i have mp3 song , it load on start.
my code read from resource, how i can read from URL ?!
thank you
Code:
NSString *pathToMusicFile = [[NSBundle mainBundle]pathForResource:@"18" ofType:@"mp3"];
myMusic = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:pathToMusicFile] error:NULL];
myMusic.delegate = self;
[myMusic play];
|
Do you mean a URL on a remote server?
The naive answer is to simply create an NSLURL that points to the file on the server and use initWithContentsOfURL just like you're doing.
However, that would cause you to do a synchronous load, which will freeze the app until the file download is done. That's bad. What you should really do is create an NSURLRequest and NSURLConnection and do an async download. That's about a page of code however. It's not hard, but a little tedious, and requires that you implement several delegate methods.