2013-10-04 84 views
0

當我NSLog BOOL成功= [videoDataDecrypted writeToFile:videopath atomically:NO]; 這種說法總是diplays沒有無法存儲視頻文件目錄

- (void) imagePickerController: (UIImagePickerController *) picker 
didFinishPickingMediaWithInfo: (NSDictionary *) info { 

NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType]; 
picker.allowsEditing = NO; 
[self dismissModalViewControllerAnimated:NO]; 

// Handle a movie capture 
if (CFStringCompare ((__bridge_retained CFStringRef)mediaType, kUTTypeMovie, 0) 
    == kCFCompareEqualTo) 
{ 

    NSString *moviePath = [[info objectForKey: 
          UIImagePickerControllerMediaURL] path]; 
    NSURL *movieURL1 = [NSURL URLWithString:moviePath]; 
    NSLog(@"moviePath %@",moviePath); 

    NSData *videoDataEncrypted = [NSData dataWithContentsOfURL:movieURL1]; 
    [videoDataEncrypted AES256EncryptWithKey:@"123"]; 

    NSData *videoDataDecrypted = [videoDataDecrypted AES256DecryptWithKey:@"123"]; 

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                 NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
    [dateFormat setDateFormat:@"dd-MM-yyyy HH:mm:SS"]; 
    NSDate *now = [[NSDate alloc] init]; 

    NSString *theDate = [dateFormat stringFromDate:now]; 

    NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"Default Album"]; 

    if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) 
     [[NSFileManager defaultManager] createDirectoryAtPath:dataPath 
            withIntermediateDirectories:NO 
                attributes:nil 
                 error:nil]; 

    NSString *videopath= [[NSString alloc] initWithString:[NSString 
           stringWithFormat:@"%@/%@.mov",documentsDirectory,theDate]]; 

    BOOL success = [videoDataDecrypted writeToFile:videopath atomically:NO]; 

    NSLog(@"Successs:::: %@", success ? @"YES" : @"NO"); 
    NSLog(@"video path --> %@",videopath); 

    NSString* urlTextEscaped = [videopath 
         stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

    NSURL *movieUrl2 = [NSURL fileURLWithPath:urlTextEscaped]; 


    UIGraphicsBeginImageContext(CGSizeMake(1,1)); 

    MPMoviePlayerViewController* theMovie = 
    [[MPMoviePlayerViewController alloc] initWithContentURL: movieUrl2]; 

    UIGraphicsEndImageContext(); 

    [self presentMoviePlayerViewControllerAnimated:theMovie]; 

    // Register for the playback finished notification 
    [[NSNotificationCenter defaultCenter] 
    addObserver: self 
    selector: @selector(myMovieFinishedCallback:) 
    name: MPMoviePlayerPlaybackDidFinishNotification 
    object: theMovie]; 

    } 
} 

回答

0

嘗試此存儲視頻,

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"Default Album"]; 

if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) 
     [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil]; 

    NSString *videopath = [NSString stringWithFormat:@"%@/%@.mov",dataPath,theDate]; 
    [videoDataDecrypted writeToFile:videopath atomically:YES]; 
+0

在上述情況下,我無法存儲視頻 –

0

試試這個方法...

#define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] 

//Open Camera 

      if ([UIImagePickerController isSourceTypeAvailable: 
       UIImagePickerControllerSourceTypeCamera]) 
      { 
     UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 

       imagePicker.delegate = self; 
       imagePicker.sourceType =UIImagePickerControllerSourceTypeCamera; 

       imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeMovie,nil]; 
       imagePicker.allowsEditing = NO; 

       [self presentViewController:imagePicker animated:YES completion:nil]; 
} 

#pragma mark - ImagePicker Controller Delegate 
-(void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    [self.popoverController dismissPopoverAnimated:true]; 

    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; 
    [self dismissViewControllerAnimated:YES completion:nil]; 
     NSString *f_name=[NSString stringWithFormat:@"%@/video1.mp4",DOCUMENTS_FOLDER]; 

     NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL]; 

     // self.movieURL=info[UIImagePickerControllerMediaURL]; 

    NSData *videoData = [NSData dataWithContentsOfURL:videoURL]; 
     //NSString* imagePath = [documentsDirectory stringByAppendingPathComponent:imageName]; 
     ////NSLog(@"image path-%@",imagePath); 

     [videoData writeToFile:f_name atomically:YES]; 
} 

讓我知道,如果你有任何問題。

+0

什麼是task_id,nn + 1? –

+0

看到我更新的答案。 – user1673099

+0

你解決了嗎? – user1673099