Accessing the front facing camera. iPhone/iPod 4 - iphone

Hey I was wondering how I can access the front facing camera. Maybe there's some guide for it?
But I don't want all buttons etc. I just want to access the from facing camera, I don't ant the button to take a photo or anything like that.

You can access the front facing camera like:
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
Check out the UIImagePickerController Class Reference

Just set the cameraDevice property of UIImagePickerController to UIImagePickerControllerCameraDeviceFront. But you should check if the device is available.

You should initiate an AVCaptureSession and specify which AVCaptureDevice to use ( AVCaptureDevicePositionFront in your case).
Start looking for the AVCaptureSession documentation and you should have a better understanding of what to do.

Well, what "Khushbu Shah" said is right. however actually the isCameraDeviceAvailable is available only ios 4 and above. Just to ensure that you opened the front camera only if it is there, the right code block to be used is as follows.
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
if([UIImagePickerController respondsToSelector:#selector(isCameraDeviceAvailable:)])
{ //check if iphone 4 and above
if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront])
{
ipc.cameraDevice=UIImagePickerControllerCameraDeviceFront;
}
}
}
[ipc release];

First thing you need to do is to detect if your device has got front-facing camera. For that you need to iterate through the video devices.
Try this method of UIImagePickerController:
+ (BOOL)isCameraDeviceAvailable:(UIImagePickerControllerCameraDevice)cameraDevice
This is a class method and UIImagePickerControllerCameraDevice can take two values:
- UIImagePickerControllerCameraDeviceRear
- UIImagePickerControllerCameraDeviceFront
Example code:
if( [UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceFront]){
// do something
}

Related

Access Photo Library via Objective-C/Xcode in iOS

I'm writing an iPhone application. I'm wondering if I can get a list of files/filenames of the photos stored in the iPhone library (or those in the simulator).
Essentially, I'm asking if I can get the filenames of the photos stored on the iPhone or simulator.
I appreciate any help, thanks!
EDIT:
image = [UIImage imageNamed:#"/Users/Library/Application Support/iPhone Simulator/5.0/Media/DCIM/100APPLE/IMG_0002.jpg"];
imageView.image = image;
doesn't work, unfortunately.
You simply have to use the UIImagePickerController.
It gives something like that:
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
// Don't forget to add UIImagePickerControllerDelegate in your .h
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
This is something of a duplicate of a SO question asked already here - Get list of all photo albums and thumbnails for each album
From that answer:
Take a look at AssetsLibrary framework.
Note that if you have access to the iOS 6 Beta, you'll want to note the changes taking place for accessing those assets. Can say no more per NDA.
Using this methods, you can easily implement that.
https://www.dropbox.com/sh/trmg44a93hwq35x/AACAVGY6VKEDR0tDUOqoxd-Ba?dl=0

Camera button on UIImagePickerController is randomly disbled

I have a UIImagePickerController (source type camera) that I use to take pictures. I have it put properly in my .h (added the #property) and .m (#synthesize). Here's what I use to show it:
if (thePicker == nil) {
thePicker = [[UIImagePickerController alloc] init];
thePicker.delegate = self;
thePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
thePicker.allowsEditing = NO;
}
[self presentModalViewController:thePicker animated:YES];
I'm having an odd problem. Every now and again, after closing/opening it a few times, the camera button OR the used button won't work (but the retake and cancel buttons work). I'm not getting any memory warnings and I have a dealloc and didReceiveMemoryWarnings void statement, but they don't get called.
ANyone else having this problem?
I have seen some apps cover it up with their overlay, but you can't remove it. AVCaptureSession really does sound more appropriate for your purposes. I see one example here:
http://www.musicalgeometry.com/?p=1273
Try this it may help u i guess Thanks!!

how to check video camera is available on iPhone

is there any way to check video camera capability available on iPhone?
Most of the camera related availability support is exposed through the UIImagePickerController. A bit tricker thing is detection of Video Camera. You can detect the presence of a video camera in a iOS device using the following method.
- (BOOL) isVideoCameraAvailable
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
[picker release];
if (![sourceTypes containsObject:(NSString *)kUTTypeMovie ]){
return NO;
}
return YES;
}
Found this code (based on UIDevice) which helped me with this issue:
https://github.com/MugunthKumar/DeviceHelper

UIImagePickerController Camera Source Problem

Ok here is the code that I wrote to display the UIImagePickerController in the camera source. I just declared the myPhotopicker in the header for the property and retain it. Synthesized it in the main code file. Then calling the picker I wrote the code below:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
if (myPhotopicker==nil) {
myPhotopicker = [[UIImagePickerController alloc] init];
myPhotopicker.delegate = self;
}// create once!
myPhotopicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:myPhotopicker animated:NO];
}
Upon calling it, there are a few things that is weird happening to the app.
Sometimes, when there are many apps running in the background (iPhone4), the app would fail to load the camera and crash the app. Though it will load CameraRoll/PhotoAlbums without problem.
If the camera view is able to load (when there are less apps running in the background), tapping the Cancel button on the camera view results in the app rebooting itself (where the Default.png image is shown quickly, and back to the main page - like when we started the app).
I have been trying to figure out this problem, but not sure what to do... pls help.. Thanks.
here is the complete code of image pickercontrol try too find solu. here.
http://www.icodeblog.com/2009/07/28/getting-images-from-the-iphone-photo-library-or-camera-using-uiimagepickercontroller/
Regards,
Shyam Parmar
Rather than your 'create once' logic try creating and releasing each time.
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
myPhotopicker = [[UIImagePickerController alloc] init];
myPhotopicker.delegate = self;
myPhotopicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:myPhotopicker animated:NO];
[myPhotopicker release];
}
You should also implement the delegate to remove the modal view controller from view when it is dismissed (if you haven't already).
You should also check that the current class conforms to the UINavigationConrollerDelegate protocol.

Basic description on how to record video in iOs 4

Hey guys i was curious if anybody could give me a very brief description of how to make an app record video in iOs 4. I know how to do all the media and whatnot using the os 3 method of using the UIImagePickerController but I do not know if that is still available in iOs4 and if not, could someone please give me a very brief description on how to do it using the new method? (No code required, but is more than welcome.)
-Thank you!
It's pretty straightforward.
I just made a view-based app with a single button on the interface to test this. The button's action is - (IBAction)shootButtonPressed;
You have to check if the device supports video recording and then configure the image picker controller to only shoot video. This code will only work on an actual device.
In the main view controller header, I made it conform to two protocols: UIImagePickerControllerDelegate and UINavigationControllerDelegate
Then I implemented the button press method like this;
- (IBAction)shootButtonPressed;
{
BOOL canShootVideo = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
if (canShootVideo) {
UIImagePickerController *videoRecorder = [[UIImagePickerController alloc] init];
videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
videoRecorder.delegate = self;
NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
NSArray *videoMediaTypesOnly = [mediaTypes filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"(SELF contains %#)", #"movie"]];
BOOL movieOutputPossible = (videoMediaTypesOnly != nil);
if (movieOutputPossible) {
videoRecorder.mediaTypes = videoMediaTypesOnly;
[self presentModalViewController:videoRecorder animated:YES];
}
[videoRecorder release];
}
}
You also have to implement two more methods to handle when a movie's shot & chosen and when the user cancels the video camera picker.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissModalViewControllerAnimated:YES];
// save the movie or something here, pretty much the same as doing a photo
NSLog(#"movie captured %#", info);
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
// process the cancellation of movie picker here
NSLog(#"Capture cancelled");
}
Super easy.
For more details, see the Multimedia Programming Guide --> About Audio and Video --> Using Video --> Recording and Editing Video. It's in the Apple Docs, although a little scattered for my taste.