我遇到问题,在录制视频后,我点击“使用”按钮将此视频保存到库中,但保存完成后,我无法点击“播放”按钮或“重新启动”按钮。这是我的代码:
-(void)actionLaunchAppCamera
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController * imagePickerController = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.showsCameraControls = YES;
imagePickerController.allowsEditing = YES;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
imagePickerController.delegate = self;
imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
[self presentModalViewController:imagePickerController animated:YES];
//[imagePickerController release];
}
}
}
保存拍摄的图像
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSURL *recordedVideoURL= [info objectForKey:UIImagePickerControllerMediaURL];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:recordedVideoURL]) {
[library writeVideoAtPathToSavedPhotosAlbum:recordedVideoURL
completionBlock:^(NSURL *assetURL, NSError *error){
[library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
NSDate* date = [asset valueForProperty:ALAssetPropertyDate];
NSLog(@"Date Time Modify %@",date);
NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat: @"dd.MM.yyyy HH:mm:ss"];
NSString* CurrentDateStamp = [formatter stringFromDate:date];
NSLog(@"NameVideo %@",asset.defaultRepresentation.filename);
NSLog(@"DateModify %@",CurrentDateStamp);
NSLog(@"Size: %lld", asset.defaultRepresentation.size);
} failureBlock:nil];
actionSheetUpload= [[UIActionSheet alloc] initWithTitle:@"Do you want to upload this video?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Upload" otherButtonTitles:nil];
actionSheetUpload.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheetUpload showInView:[UIApplication sharedApplication].keyWindow];
[actionSheetUpload release];
}
];
}
[library release];
}
有什么想法吗?提前致谢
答案 0 :(得分:0)
该代码适用于保存视频,如果你想让它播放。然后你需要使用播放器来播放它。
例如:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSURL *recordedVideoURL= [info objectForKey:UIImagePickerControllerMediaURL];
.// Save Your Stuff
.
.
MPMoviePlayerController *movieplayer =[[MPMoviePlayerController alloc] initWithContentURL: recordedVideoURL];
[[movieplayer view] setFrame:
[self.view bounds]];
[self.view addSubview:
[movieplayer view]];
[movieplayer play];
}
编辑:
对于上传视频,根据您的代码:
声明NSURL *recordedVideoURL;
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//NSLog(@"but ind %d", buttonIndex);
if (buttonIndex == uploadBTnIndex) {
NSData *videoData = [NSData dataWithContentsOfURL:recordedVideoURL];
//Use this NSData to upload, So what else your problem to upload using web Services ?
}
答案 1 :(得分:0)
也许你不会用- (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^)(void))completion