来自摄像机视频的数据返回零

时间:2014-04-27 22:44:28

标签: ios objective-c url nsdata

这是我从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];

归零吗?为什么它显然显示数据?

1 个答案:

答案 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]);