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
Related
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.
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
}
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.
HI,
I need to record video using iPhone. To do that i used UIImagePickerController. I have an iPhone 3G, with me. when i run my code to check if source type available it says device not supported. My OS is 3.2.1, where i am wrong, can some one tell me what i need to change.
Also is there some other way to record video. What i need to do is to get the video stream as it is recorded.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
NSArray *sourceTypes =
[UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
if (![sourceTypes containsObject:(NSString *)kUTTypeVideo ]){
NSLog(#"device not supported");
return;
}
//picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeVideo];
picker.videoQuality = UIImagePickerControllerQualityTypeHigh;
[self presentModalViewController:picker animated:YES];
Thanks,
That is because the 3G isn't supported for video recording.
Lance is correct. The native UIImagePickerController does not work on iPhone 3G. If an app does do video recording on a 3G they are doing a hack like taking multiple photos in succession and manually encoding a video file using the individual images.
I am using UIImagePickerController to record a video with the sourceType set to UIImagePickerControllerSourceTypeCamera.
I have set allowsEditing to true so that the video can be edited before the picker returns. But after I edit the video using the trimming interface and press "Pick", I only get back the original recording in the delegate, not the trimmed version. What am I doing wrong? I am using iPhone OS 3.1.3. I remember this used to work in an earlier version but it seems to be failing in the latest OS. Any help is appreciated?
By the way i confirmed that if the source of the video is UIImagePickerControllerSourceTypeSavedPhotosAlbum, the trimming works in version 3.1.3. So trimming with source as the camera is failing. Interestingly with the camera-roll/photos-album as the source, a "Choose" button appears and soon after clicking it, the controller displays a message saying the "Video is being trimmed ... ". I don't get this message when using the camera source.
Here is a snippet of the code I am using to record a video using the camera source.
- (void) recordVideo {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
picker.videoQuality = UIImagePickerControllerQualityTypeHigh;
[self presentModalViewController:picker animated:YES];
[picker release];
}
My delegate implementation is as follows:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo: (NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
self.videoPath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
...
}
Thanks a lot,
kris.
Just ran into this myself ... and found this post when looking for a solution.
looks like the only way around this is to copy the file to your app's directory, then open the UIVideoEditorController ...
Anyone know if this UIImagePickerController newly-captured video not being trimmed issue is a bug in the SDK, or are we doing something wrong?