shivam
shivam

Reputation: 1140

Show remaining time in video recorder in iphone

I want to show remaining time on video recorder. Currently it is showing recording time. How can i?

My code is :

UIImagePickerController*  Videopicker1 = [[UIImagePickerController alloc] init];
Videopicker1.delegate = self;
Videopicker1.sourceType = UIImagePickerControllerSourceTypeCamera;
Videopicker1.showsCameraControls = YES;
Videopicker1.videoQuality=UIImagePickerControllerQualityTypeLow;
Videopicker1.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie]; // kUTTypeMovie is actually an NSString.
Videopicker1.videoMaximumDuration = 30.0f; // limits video length to 30 seconds.
[self presentModalViewController:Videopicker1 animated:YES];

Thanks in advance.

Upvotes: 3

Views: 2871

Answers (2)

Bishal Ghimire
Bishal Ghimire

Reputation: 2600

On your VC.h file

@interface VideoCaptureVC_iPhone : UIViewController
<UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
    UIImagePickerController *picker;
    NSTimer *videoTimer;

}

@property (nonatomic, retain) NSTimer *videoTimer;

On your vc.m file

- (void)pickerCameraSnap:(id)sender{
    NSLog(@"start camera capture and timer");
    [picker startVideoCapture];
    self.videoTimer =  [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeValue) userInfo:nil repeats:YES];
}

make a calculation as per your need and change the text @"TimeRemaining" in proper place i have rotated text for landscape view !

-(void)changeValue{
    UILabel *textNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 30, 100, 100)];
    textNameLabel.center = CGPointMake(30,285);
    textNameLabel.backgroundColor = [UIColor redColor];
    textNameLabel.text = @"TimeRemaining";
    textNameLabel.textColor = [UIColor whiteColor];
    CGAffineTransform transformRotate = CGAffineTransformMakeRotation((M_PI  / 2));
    textNameLabel.transform = transformRotate;

    UIView *myOverlay = [[UIView alloc] initWithFrame:self.view.bounds];
    UIImage *overlayImg = [UIImage imageNamed:@"CameraOverlay"];
    UIImageView *overlayBg;
    overlayBg = [[UIImageView alloc] initWithImage:overlayImg];
    [myOverlay addSubview:overlayBg];
    [myOverlay addSubview:textNameLabel];
    [picker setCameraOverlayView:myOverlay];
}

and finally to stop the timer

- (void)stopCamera:(id)sender{
    NSLog(@"stop camera");
    [self.videoTimer invalidate]; 

    [picker stopVideoCapture];
    [picker setCameraDevice:UIImagePickerControllerCameraDeviceRear];
}

Upvotes: 3

Sean Lintern
Sean Lintern

Reputation: 3141

As you have set a video maximum time, and you state you are currently showing the current duration.

TimeRemaining = videoMaximumDuration - currentDuration; 

Upvotes: 0

Related Questions