【问题标题】:Secretly record a movie using UIImagePickerController使用 UIImagePickerController 偷偷录制电影
【发布时间】:2012-08-16 13:30:40
【问题描述】:

我正在为 iPhone 4/4S 制作密码应用程序。当用户输入密码 3 次失败时,我想使用 iPhone 的前置摄像头制作用户的电影。这并不是什么新鲜事,应用商店中的许多应用都在做类似的事情。给这个人拍照,获取他的 GEO 坐标等。

我面临的挑战是,当我尝试设置电影录制时,相机覆盖会占据整个屏幕。我真正想做的是让用户仍然看到登录屏幕和按钮,但偷偷录制并制作用户的电影。有没有办法我可以做到这一点?

这是我正在使用的代码。

在我的 *.h 文件中

@interface v1InstantController : UIViewController <UIImagePickerControllerDelegate>
{   
    UIImagePickerController *picpicker;
}

@property (nonatomic, retain) UIImagePickerController *picpicker;

在我的 *.m 文件中

-(IBAction) makeMovieNow
{
    picpicker = [[UIImagePickerController alloc] init];
        picpicker.delegate = self;


        picpicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        picpicker.sourceType = UIImagePickerControllerSourceTypeCamera;

        picpicker.showsCameraControls = NO;
        picpicker.navigationBarHidden = YES;
        picpicker.wantsFullScreenLayout = NO;

        picpicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
        picpicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;

        picpicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
        picpicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;

        picpicker.videoQuality = UIImagePickerControllerQualityTypeHigh;

        picpicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];

        //The problem is right here! 
        //picpicker.cameraViewTransform = CGAffineTransformScale(picpicker.cameraViewTransform, 0.01, 0.01);
        [self presentModalViewController:picpicker animated:YES];

        [picpicker startVideoCapture];
}

问题就在这里“presentModalViewController:picpicker”。当我使用它时,它会启动带有虹膜飞溅等的相机屏幕,并显示整个屏幕上正在记录的内容。即使我使用 cameraViewTransform,它仍然会禁用页面上的任何内容并将此相机叠加层放在页面中间。 (有一个非常小的相机覆盖)我不希望用户知道我正在录制并且希望他认为它照常营业。即让他继续尝试在页面上输入密码失败。

【问题讨论】:

    标签: iphone ios xcode xcode4 uiimagepickercontroller


    【解决方案1】:

    UIImagePickerController 提供了一种从用户那里轻松获取照片/视频的方法,因此用户始终可以看到它。

    由于您似乎需要更多控制权,您可以查看 AVFoundation。 Apple Documentation 应该提供一个很好的起点。

    【讨论】:

    • 有几个示例项目可用:AVCam 用于基础知识,SquareCam 也可能很有趣。
    【解决方案2】:

    这里是任何可能对未来感兴趣的人的答案。给它评分!

    确保包含 coreVideo 和 CoreMedia 框架

    在您的 *.h 文件中

    @interface v1InstantController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate>
    {
        AVCaptureSession *session;
        NSString *videoPath2;
    }
    
    @property (nonatomic, retain) AVCaptureSession *session;
    @property (nonatomic, retain) NSString *videoPath2;
    

    在您的 *.m 文件中

    @synthesize session;
    @synthesize videoPath2;
    
    -(IBAction) makeMovieNow
    {
    
        NSLog(@"makeMovieNow ..");
    
        //record movie
        session = [[AVCaptureSession alloc] init];
        [session beginConfiguration];
        session.sessionPreset = AVCaptureSessionPresetHigh;
    
        AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
        captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    
    
        NSError *error = nil;
        AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        device = [self frontFacingCameraIfAvailable];
        AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
        if (!videoInput) 
        {
            // Handle the error appropriately.
            NSLog(@"ERROR: trying to open camera: %@", error);
        }
    
        AVCaptureDevice *audioDevice     = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeAudio];
        AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error ]; 
    
    
        AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
    
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectoryPath = [paths objectAtIndex:0];
        NSString *movieFileName = [NSString stringWithFormat: @"Secret.mov"];
        NSString *fullPathToFile2 = [documentsDirectoryPath stringByAppendingPathComponent:movieFileName];
        NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:fullPathToFile2];
    
        videoPath2=[outputURL path];
    
    
        [session addInput:videoInput];
        [session addInput:audioInput];
        [session addOutput:movieFileOutput];
        [session commitConfiguration];
    
        //start recording
        [session startRunning];
        [movieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
    }
    
    -(IBAction) makeMovieStop
    {
        NSLog(@"makeMovieStop ...");
    
        //stop recording
        [session stopRunning];
    
        //save video to photo-album
        UISaveVideoAtPathToSavedPhotosAlbum(videoPath2, self, nil, nil);
    
    }
    

    【讨论】:

      猜你喜欢
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      • 2015-09-07
      • 1970-01-01
      • 1970-01-01
      • 2018-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多