开发者

check video file size before playing on iphone

开发者 https://www.devze.com 2023-01-17 04:23 出处:网络
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.

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

精彩评论

暂无评论...
验证码 换一张
取 消