Hi i am getting video in the sameViewController when i clicked video button in same View..But my requirement is want to get video in to secondViewController when we click video button in firstView ..i written code like this
//mainViewController.m
-(IBAction)videoClicked:(id)sender
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes =[[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
[self presentViewController:imagePicker animated:YES completion:nil];
}
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:#"public.movie"]){
videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(#"videourl %#",videoURL);
}
ViewController *viewC=[[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
[picker presentViewController:viewC animated:YES completion:nil];
}
please anybody help me how to do this .help is appreciated
You can create property for videoUrl in your secondViewController and set it before presenting.
Related
I am trying to browse an image and display in imageview using UIImagePickerController. Basically the view I am using to browse the image is based on navigationController.
But using the below code after I select the image and come back to view, I can see that the view is flickering to left right and the image is not showing in image view.
Actually the entire source code is quit long, thats why I post the image picker part only. If required I can post more code.
RegistrationFormViewController.h
#interface RegistrationFormViewController : ViewController
<UIImagePickerControllerDelegate,UINavigationControllerDelegate,CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
UIImagePickerController *imagePickerController;
}
#property (strong, nonatomic) CLLocationManager *locationManager;
#property (weak, nonatomic) IBOutlet UIImageView *imageUser;
- (IBAction)registerBt:(id)sender;
RegistrationFormViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
_barButtonBack.target = self.revealViewController;
_barButtonBack.action = #selector(revealToggle:);
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapDetected)];
singleTap.numberOfTapsRequired = 1;
[self.imageUser setUserInteractionEnabled:YES];
[self.imageUser addGestureRecognizer:singleTap];
}
-(void)tapDetected{
NSLog(#"single Tap on imageview");
imagePickerController = [[UIImagePickerController alloc]init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePickerController animated:YES completion:nil];
}
#pragma mark - ImagePickerController Delegate
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
// Dismiss the image selection, hide the picker and
//show the image view with the picked image
[picker dismissViewControllerAnimated:YES completion:nil];
[self.imageUser setImage:image];
self.imageUser.contentMode = UIViewContentModeScaleAspectFill;
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
There is no issue in your code that you showed here. However try this in didFinishPickingImage -
dispatch_async(dispatch_get_main_queue(), ^{
self.imageUser.contentMode = UIViewContentModeScaleAspectFill;
[self.imageUser setImage:image];
});
and move this code to viewDidLoad
imagePickerController = [[UIImagePickerController alloc]init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
you can also check whether you are getting the image or not using breakpoint.
try this delegate method
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
In viewcontroller.m file, just put this code:
#import <AssetsLibrary/AssetsLibrary.h>
typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset);
typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);
- (IBAction)Gallery:(id)sender {
self.ImagePickerController = [[UIImagePickerController alloc]init];
self.ImagePickerController.delegate = self;
self.ImagePickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:self.ImagePickerController animated:YES completion:nil];
}
- (IBAction)Camera:(id)sender {
self.ImagePickerController = [[UIImagePickerController alloc]init];
self.ImagePickerController.delegate = self;
self.ImagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:self.ImagePickerController animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
[picker dismissViewControllerAnimated:YES completion:nil];
NSURL *imageUrl = (NSURL *)[info objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *representation = [myasset defaultRepresentation];
CGImageRef resolutionRef = [representation fullResolutionImage];
if (resolutionRef) {
UIImage *image = [UIImage imageWithCGImage:resolutionRef scale:1.0f orientation:(UIImageOrientation)representation.orientation];
self.SelectedImage.image =image;
}
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(#"cant get image - %#",[myerror localizedDescription]);
};
if(imageUrl)
{
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc]init];
[assetslibrary assetForURL:imageUrl resultBlock:resultblock failureBlock:failureblock];
}
}
In viewcontroller.h file
#interface ViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
#property (nonatomic)UIImagePickerController *ImagePickerController;
#property (weak, nonatomic) IBOutlet UIImageView *SelectedImage;
This code for capturing image one by one from camera,but after taking one image next time camera will open but with black screen(like it,s shutter close).all other ios version its working,but not working in ios 8.please tell me how can i solve it?
-(void)openCamera
{
if(![PickerHandler doesDeviceSupportMediaType:ITEM_TYPE_PHOTO])
{
[PickerHandler showNoDeviceSupportWarningForMediaType:ITEM_TYPE_PHOTO withDelegate:self];
}
else
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
[self presentViewController:picker animated:YES completion:nil];
}
}
Go to Settings > Privacy > Pictures ... and check if your app have permission.
In the code, use this to verify camera access.
- (BOOL)authorizedCameraAccess
{
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
return (status == AVAuthorizationStatusAuthorized);
}
this code is not work in simulator.
UIImagePickerController *videoScreen = [[UIImagePickerController alloc] init];
videoScreen.sourceType = UIImagePickerControllerSourceTypeCamera;
videoScreen.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
videoScreen.allowsEditing = NO;
videoScreen.delegate = self;
[self presentViewController:videoScreen animated: YES completion:NO];
Implement This method
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissViewControllerAnimated:NO completion:NO];
}
In my application i need to take video from simulator and i need to upload to server.can any one help to me.Please provide any solution as soon as possible.
Thanks & Regards
T.swathi
First, create a UIImagePickerController
On your class, you will need to implement the UIImagePickerControllerDelegate protocol and wire it up to the delegate property on the picker. You should be able to get the location of the media selected from didFinishPickingMediaWithInfo once the user has selected something.
//Check in iOS Device not in Simulator
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// this is the file system url of the media
NSURL* videoUrl = [info objectForKey:UIImagePickerControllerMediaURL];
// TODO: read in data at videoUrl and write upload it to your server
}
Use this function may be help full
-(void)selectVideoButtonClicked:(id)sender{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
[self presentViewController:imagePicker animated:YES completion:nil];
}
and take delege of "UIImagePickerControllerDelegate" & and import framework and using delegate function pick video from library
MobileCoreServices.framework first import in project and after than import in file CoreServices/CoreServices.h
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
// Handle a movie capture
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0)
== kCFCompareEqualTo) {
NSString *moviePath = [[info objectForKey: UIImagePickerControllerMediaURL] path];
NSLog(#" Video Path %#",moviePath);
NSString *fileName = [[NSString alloc]init];
//If you wants get File Name Then you can use this
if ([moviePath rangeOfString:#"//"].location != NSNotFound) {
NSString *separatorString = #"//";
NSArray *disSplit = [moviePath componentsSeparatedByString:separatorString];
fileName = disSplit[1] ;
// [self videoUploadingDirect:moviePath];
}
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
}
}
[self dismissViewControllerAnimated:YES completion:nil];
}
Thanks :)
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 am trying to push a view controller (for extra editing) from UIImagePickerController after user has selected an image.
It is successfully pushed.
But when that view controller is popped and user return to the editing screen, the editing screen is no longer interactable. Does anyone know what is the problem.
-(void)didTapBtn:(id)sender
{
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.picker.delegate = self;
self.picker.allowsEditing = YES;
[self presentViewController:self.picker animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
if (image == nil) {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
if (image == nil) {
return;
}
self.test = [[BTTestViewController alloc] init];
self.test.delegate = self;
[self.picker pushViewController:self.test animated:YES];
}
//Called by BTTestViewController
-(void)didCancel
{
[self.picker popViewControllerAnimated:YES];
}
try this one it work in my application:
UIImagePickerController *imagePicker;//put it in .h file
put it in .m file
imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"STEP-BY-STEP-STORY!" message: #"Camera is not available" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *pickedImage = [info objectForKey:UIImagePickerControllerEditedImage];
imageData.image =[self resizeImage:imageData.image width:200 height:200];
[picker dismissViewControllerAnimated:YES completion:nil];
iphone_filtersViewController *nav=[[iphone_filtersViewController alloc]initWithNibName:#"iphone_filtersViewController" bundle:nil];
[self.navigationController pushViewController:nav animated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
// release Picker
[picker dismissViewControllerAnimated:YES completion:nil];
}
// iphone_filtersViewController method
-(IBAction)backButton
{
[self.navigationController popViewControllerAnimated:YES];
}
may be it will help.