这是我从UIImagePickerController
获取视频的代码:
- (IBAction)takeVideo:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)viewDidAppear:(BOOL)animated {
self.movieController = [[MPMoviePlayerController alloc] init];
self.movieController.controlStyle = MPMovieControlStyleNone;
[self.movieController setContentURL:self.movieURL];
[self.movieController.view setFrame:CGRectMake (15, 125, 292, 390)];
self.movieController.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.movieController.view];
[self.movieController play];
NSString *myString = [self.movieURL absoluteString];
NSData *videoData = [NSData dataWithContentsOfFile:myString];
NSLog(@"%@",[NSByteCountFormatter stringFromByteCount:videoData.length countStyle:NSByteCountFormatterCountStyleFile]);
[self setImageDataToSend:videoData];
}
其中:
NSString *myString = [self.movieURL absoluteString];
NSData *videoData = [NSData dataWithContentsOfFile:myString];
NSLog(@"%@",[NSByteCountFormatter stringFromByteCount:videoData.length countStyle:NSByteCountFormatterCountStyleFile]);
[self setImageDataToSend:videoData];
归零吗?为什么它显然显示数据?
答案 0 :(得分:2)
获得这样的大小
NSError *error = nil;
NSDictionary *attributes = [[NSFileManager defaultManager]
attributesOfItemAtPath:[self.movieURL path] error:&error];
if (!error) {
NSLog(@" size= %@",[attributes objectForKey:NSFileSize]);
}else{
NSLog(@"err= %@",error);
}
如果你想要KB
NSString *myString = [self.movieURL path];
NSData *videoData = [NSData dataWithContentsOfFile:myString];
NSLog(@"%@",[NSByteCountFormatter stringFromByteCount:videoData.length countStyle:NSByteCountFormatterCountStyleFile]);