I want to display the saved videos in Photo Library in popOver controller just like images.
How can i show the videos in popOver controller?
My code for Images is as follow:
if ([self.popoverController isPopoverVisible]) {
[self.popoverController dismissPopoverAnimated:YES];
[popoverController release];
} else {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];
popoverController.delegate = self;
[self.popoverController presentPopoverFromRect:CGRectMake(100, 100, 150, 100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[imagePicker release];
Help me to solve this problem.
Thank you,
You have to choose right mediaType:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
//here
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
imagePicker.delegate = self;
Related
I want to choose video from PhotosAlbum, follows this code, NOW I can choose video but can not go delegate method:
imagePickerController:didFinishPickingMediaWithInfo:
I don't know why, any help is appreciated.
UIImagePickerController*m_pPickerController = [[UIImagePickerController alloc] init];
[m_pPickerController setEditing:NO];
m_pPickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
m_pPickerController.delegate = self;
m_pPickerController.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
m_pPickerController.delegate = self;
m_pPickerController.videoQuality=UIImagePickerControllerQualityTypeLow;
[self presentViewController:m_pPickerController animated:YES completion:^{
m_pPickerController.delegate = self;
}];
This is an issue reported at crashlytics. I am getting this(I assume) when I load image picker and dismiss. I only got this once. But it got something to do with image picker or navigation controller. Does any one know the cause?
Update
Image picker camera is loaded like this.
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.delegate = self;
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
{
[[UIDevice currentDevice]setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeRight] forKey:ORIENTATION_STRING];
} else {
[[UIDevice currentDevice]setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:ORIENTATION_STRING];
}
self.imagePickerController = imagePickerController;
[self.navigationController presentViewController:self.imagePickerController animated:YES completion:nil];
for other source types, I am using the following code.
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
popOver = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
self.imagePickerController = imagePickerController;
popOver.delegate = self;
CGRect popOverRect = sender.frame;
[popOver presentPopoverFromRect:popOverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
Add UIIMagePickerController to ContainerView. & then to view
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
[self addChildViewController:picker] ;
[picker didMoveToParentViewController:self] ;
[self.view addSubview:picker.view] ;
while removing pickercontroller do
[picker.view removeFromSuperview] ;
[picker removeFromParentViewController] ;
I am using the UIImagePickerController to let the user select a photo or video. The problem I am facing, is I use my own image editor for photo's so want allowsEditing=NO for photo's, but video must be a certain length so I want allowsEditing=YES for video.
Setting videoMaximumDuration for the image picker works fine when recording video, but if selecting from the camera roll it only informs the user that the video is too long if allowsEditing is enabled.
So far, I can successfully change the allowsEditing property when using the camera by listening for the ImageControlModeChanged notification. Then I can change the property using:
- (void)imageCaptured:(NSNotification *)notification
{
if (imagePicker.cameraCaptureMode == UIImagePickerControllerCameraCaptureModeVideo) {
imagePicker.allowsEditing = YES;
} else {
imagePicker.allowsEditing = NO;
}
}
However this doesn't work when selecting from the Camera roll. I have monitored the notifications and can't see one that would be useful to change the allowsEditing property depending on which item was selected.
Is this even possible?
Thanks
Why not creating 2 or even 4 UIImagePickerControllers instead of messing around with notifications?
- (void) useCamera
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
- (void) useCameraRoll
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
- (void)videoRoll
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = YES;
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
- (void)vidCam
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
Edit:
After better understanding of the question I don't think it's possible. There are a few notification you can use but those are not documented anywhere or working on iOS7. If that is really the case the best solution I can think of is to use a 3rd party such as github.com/andrei200287/SAVideoRangeSlider and allowsEditing = NO for everything.
Simply allow editing on both image and video pick, but in didFinishPicking delegate method, for photo, choose original photo and not edited photo. However picker will still show that square box over image.
Try this
assign properties in view did load , not in imageCaptured method. it works fine
videoController.delegate = self;
videoController.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
videoController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:videoController.sourceType];
videoController.allowsEditing = YES;
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
This code make crash EXC_BAD_ACCESS on ios7 devices.
On iOS6 - all okay, and UIImagePickerControllerSourceTypePhotoLibrary work normal.
To work with camera
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
(NSString *) kUTTypeMovie, nil];
[self presentViewController:imagePickerController animated:YES completion:nil]; }
I have the method, that take photos from gallery or from the camera
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
But when i run it on the simulator, code doesnt work. And it doesnt work in picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum and picker.sourceType = UIImagePickerControllerSourceTypeCamera
Is the problem in the simulator or in the code?
Try this,
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
else
{
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self.navigationController presentModalViewController:picker animated:NO];
If you are creating the app for iPad. You will have to present the gallery in a popOver control.
Swift 3/4/5 verison:
if UIImagePickerController.isSourceTypeAvailable(.camera) {
picker.sourceType = .camera
}
else {
picker.sourceType = .savedPhotosAlbum // or .photoLibrary
}
Swift 2 version:
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
picker.sourceType = .Camera
}
else {
picker.sourceType = .SavedPhotosAlbum // or .PhotoLibrary
}
In simulator, you can't use cameraCaptureMode and showsCameraControls.
In simulator your picker.sourceType = UIImagePickerControllerSourceTypeCamera wont be called as there is no camera available in simulator. Also its a good practice to check whether the source type is available to avoid crashes.
#import <MobileCoreServices/UTCoreTypes.h>
….
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePickerCamera =[[UIImagePickerController alloc] init];
imagePickerCamera.delegate = self;
imagePickerCamera.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePickerCamera.allowsEditing = YES;
imagePickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imagePickerCamera animated:YES completion:nil];
}
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePickerAlbum =[[UIImagePickerController alloc] init];
imagePickerAlbum.delegate = self;
imagePickerAlbum.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePickerAlbum.allowsEditing = YES;
imagePickerAlbum.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePickerAlbum animated:YES completion:nil];
}
Similarly to the above answers, but I found this easier. Show a pop up alert if the device doesn't have a camera (like the simulator). Sam code, different usage:
//button if to take a photo
- (IBAction)takePhoto:(id)sender {
//checks if device has a camera
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *noCameraAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"You don't have a camera for this device" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
//shows above alert if there's no camera
[noCameraAlert show];
}
//otherwise, show a modal for taking a photo
else {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imagePicker animated:YES completion:NULL];
}
}