Graphics Programs Reference
In-Depth Information
straints.) Therefore, recorded video is written to disk in a temporary directory. When the
user finalizes the video recording, imagePickerControl-
ler:didFinishPickingMediaWithInfo: is sent to the image picker controller's
delegate, and the path of the video on the disk is in the info dictionary. You can get the
path like so:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *mediaURL = [info objectForKey:UIImagePickerControllerMediaURL];
}
We will talk about the filesystem in Chapter 14 , but what you should know now is that the
temporary directory is not a safe place to store the video. It needs to be moved to another
location.
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *mediaURL = [info objectForKey:UIImagePickerControllerMediaURL];
if (mediaURL) {
// Make sure this device supports videos in its photo album
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([mediaURL path])) {
// Save the video to the photos album
UISaveVideoAtPathToSavedPhotosAlbum([mediaURL path], nil, nil, nil);
// Remove the video from the temporary directory it was saved at
[[NSFileManager defaultManager] removeItemAtPath:[mediaURL path]
error:nil];
}
}
}
That is really all there is to it. There is just one situation that requires some additional in-
formation: suppose you want to restrict the user to choosing only videos. Restricting the
user to images is simple (leave mediaTypes as the default). Allowing the user to choose
between images and videos is just as simple (pass the return value from availableMe-
diaTypesForSourceType: ). However, to allow video only, you have to jump
through a few hoops. First, you must make sure the device supports video, and then you
must set the mediaTypes property to an array containing the identifier for video only.
NSArray *availableTypes = [UIImagePickerController
availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
if ([availableTypes containsObject:(NSString *)kUTTypeMovie])
[ipc setMediaTypes:[NSArray arrayWithObject:(NSString *)kUTTypeMovie]];
Wondering why kUTTypeMovie is cast to an NSString ? This constant is declared as:
const CFStringRef kUTTypeMovie;
Search WWH ::




Custom Search