2014-01-22 55 views
0

我记录视频后出现问题,点击使用按钮将此视频保存到库中,但保存完成后,我无法点击播放按钮或重拍按钮。这是我的代码:单击UIImagepickercontroller中的使用按钮后无法点击ios

-(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]; 
} 

任何想法的形象呢?在此先感谢

+1

又在哪里是玩的代码..?您只是保存视频,之后需要播放视频 –

+0

保存视频后,我会将此视频上传到服务器。我更新了我的问题中的代码。 – user3214941

+1

然后你应该使用播放器来播放它。 –

回答

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 ? 
} 
+0

谢谢,但我不需要播放视频。我只需要将其上传到服务器。 – user3214941

+0

然后是什么问题,你问我做完(保存)后上传的代码。 –

+0

我的问题是点击使用视频后,它会显示工作表上传,然后我点击工作表上的取消,以支持UIImagePickercontroller,但UIImagePickerController似乎无法点击任何按钮。 – user3214941

0

也许你不排除选择器与- (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^)(void))completion