Graphics Programs Reference
In-Depth Information
For the More Curious: Recording Video
Once you understand how to use UIImagePickerController to take pictures, mak-
ing the transition to recording video is trivial. Recall that an image picker controller has a
sourceType property that determines whether an image comes from the camera, photo
library, or saved photos album. Image picker controllers also have a mediaTypes prop-
erty, which is an array of strings that contains identifiers for what types of media can be se-
lected from the three source types.
There are two types of media a UIImagePickerController can select: still images
and video. By default, the mediaTypes array only contains the constant string
kUTTypeImage . Thus, if you do not change the mediaTypes property of an image
picker controller, the camera will only allow the user to take still photos, and the photo lib-
rary and saved photos album will only display images.
Adding the ability to record video or choose a video from the disk is as simple as adding
the constant string kUTTypeMovie to the mediaTypes array. However, not all devices
support video through the UIImagePickerController . Just like the class method
isSourceTypeAvailable: allows you to determine if the device has a camera, the
availableMediaTypesForSourceType: method checks to see if that camera can
capture video. To set up an image picker controller that can record video or take still im-
ages, you would write the following code:
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
NSArray *availableTypes = [UIImagePickerController
availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
[ipc setMediaTypes:availableTypes];
[ipc setSourceType:UIImagePickerControllerSourceTypeCamera];
[ipc setDelegate:self];
Now when this image picker controller interface is presented to the user, there will be a
switch that allows them to choose between the still image camera or the video recorder. If
the user chooses to record a video, you need to handle that in the UIImagePickerCon-
troller delegate method imagePickerControl-
ler:didFinishPickingMediaWithInfo: .
When dealing with still images, the info dictionary that is passed as an argument contains
the full image as a UIImage object. However, there is no “UIVideo” class. (Loading an
entire video into memory at once would be tough to do with iOS device memory con-
Search WWH ::




Custom Search