Reputation: 55
I want to get the duration of a mp3 file from the internet,I use the following code:
NSURL *url = [NSURL fileURLWithPath:@"http://view.33591.com:586/2012/11/30/11/4207369.mp3"];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url
options:nil];
CMTime time = asset.duration;
float seconds = CMTimeGetSeconds(time);
NSLog(@"seconds:%f",seconds);
but it always returns 0,if I change the url to a local file from the bundle,it works fine.So is there a way to do that correctly?
Upvotes: 0
Views: 540
Reputation:
NSURL *url = [NSURL fileURLWithPath:@"http://view.33591.com:586/2012/11/30/11/4207369.mp3"];
The URL you provide is not a filesystem path. Use [NSURL URLWithString:]
instead, and do read the documentation of the NSURL
class and in particular the methods you are seeking to use.
fileURLWithPath:
Initializes and returns a newly created NSURL object as a file URL with a specified path.
(emphasis mine)
Upvotes: 1