For the More Curious:Recording Video


#1

Has anyone else tried this? I couldn’t get it to work. The video/camera switch shows up but I’m unable to change it to video, it’s stuck on camera.

Also the implementation of imagePickerController: didFinishPickingMediaWithInfo: seems to be incomplete. I replaced the one from the chapter with this new one and it would get wedged after selecting either use photo or retake. I did a merge of the old with the new, putting the new as an else from the initial if and it would then work for the camera but still could not select the video.

Here is my imagePickerController: didFinishPickingMediaWithInfo:

[code]- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// if added to add video to app
NSURL *mediaURL = info[UIImagePickerControllerMediaURL];
if (mediaURL) {
//make sure this device supports videos in its photo album
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([mediaURL path])){

        // save the video to photos album
        UISaveVideoAtPathToSavedPhotosAlbum([mediaURL path], nil,nil,nil);
        
        // remove the video from the temporary directory
        [[NSFileManager defaultManager] removeItemAtPath:[mediaURL path] error:nil];
    }
        
} else {
        // get picked image from info directory
        UIImage *image = info[UIImagePickerControllerOriginalImage];
    
        // store the image in the BNRImageStore for this key
        [[BNRImageStore sharedStore]setImage:image
                                      forKey:self.item.itemKey];
    
        // put that image onto the screen in our image view
        self.imageView.image = image;

        // take image picker off the screen -
        // you must call this dismiss method
        [self dismissViewControllerAnimated:YES completion:nil];
}

}
[/code]

The other thing that changed was takePicture:

[code]- (IBAction)takePicture:(id)sender {

UIImagePickerController *imagePicker = [[UIImagePickerController alloc ]init];

// if the device has a camera, take a picture, otherwise
// just pick from photo library
if ([UIImagePickerController
     isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
} else {
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}

//  next three lines are from for the more curious: recording video
NSArray *availableTypes = [UIImagePickerController
                           availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
imagePicker.mediaTypes = availableTypes;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;


imagePicker.delegate = self;

// PLACE IMAGE PICKER ON THE SCREEN
[self presentViewController:imagePicker animated:YES completion:nil];

}[/code]


#2

Ok so I’m an idiot. I figured out the switch thing, it’s a slide switch. Thing wedges after taking video. Slider at the top selecting frames still responds but not the use video, play or retake buttons. I’m guessing that since it is not responding there is some protocol method that I need to implement to get it to work.

John


#3

I’m slowly getting this to work. I “unweged” things by moving this line out side of the if/else:

        [self dismissViewControllerAnimated:YES completion:nil];

Now it goes back to the item detail but doesn’t display the video or have any option to play it.

John


#4

Here is my code. I can record a video in detail view and see it from the photo library. However, if I remove the video from tmp folder by calling removeItemAtPath as in the book, the video doesn’t show up in the photo library. I thought UISaveVideoAtPathToSavedPhotosAlbum would make a copy, but it seems not.

- (IBAction)takePicture:(id)sender {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        NSArray *availableTypes = [UIImagePickerController
                                   availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
        imagePicker.mediaTypes = availableTypes;
    } else {
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;

    [self presentViewController:imagePicker animated:YES completion:nil];
}

- (void)imagePickerController:(UIImagePickerController *)picker
                      didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    if (info[UIImagePickerControllerMediaURL]) {
        NSURL *mediaURL = info[UIImagePickerControllerMediaURL];
        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([mediaURL path])) {
            UISaveVideoAtPathToSavedPhotosAlbum([mediaURL path], nil, nil, nil);
//        [[NSFileManager defaultManager] removeItemAtPath:[mediaURL path] error:nil];
        }
    } else {
        UIImage *image = info[UIImagePickerControllerEditedImage];
        //UIImage *image = info[UIImagePickerControllerOriginalImage];
        [[BNRImageStore sharedStore] setImage:image forKey:self.item.itemKey];
        self.imageView.image = image;
    }

    [self dismissViewControllerAnimated:YES completion:nil];
}