I am working on an iphone app that downloads a video from a web server and then plays this video. my problem is that sometimes the server replies to me with an empty file not a valid video. how can i check that this is a valid video file before playing?
player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@sel开发者_如何学Goector(didFinishPlaying:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
player.controlStyle = MPMovieControlStyleFullscreen;
[player play];
You can check file size with help of NSFileManager:
NSFileManager* manager = [[NSFileManager alloc] init];
NSError* error;
NSDictionary* attributes = [manager attributesOfItemAtPath:[url path] error:&error];
int size = [attributes fileSize];
精彩评论