2014-04-27 68 views
1

這是我正從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

什麼樣的Xcode顯示,當您登錄 - >的NSLog(@ 「%@」,self.movi​​eURL); –

+0

@AnandK'file:/// private/var/mobile/Applications/F8D3F96F-E837-4F2A-9064-AB0DA1E092BD/tmp/capture-T0x17806a140.tmp.KkRRxZ/capturedvideo.MOV' – maxisme

回答

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