当我的NSLog BOOL成功= [videoDataDecrypted writeToFile:videopath atomically:NO]; 这个陈述总是在没有
- (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 :(得分: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];
答案 1 :(得分: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];
}
如果您有任何问题,请与我们联系。