How to access Iphone camera in video Mode - ios

I need to implement video Recording in my IPhone App. How can i access IPhone camera in Video mode for capturing videos.Plz provide some useful Links.

First of all you want to add MediaPlayer.framework then -
Import mediaplayer framework on .h file.
#import <MediaPlayer/MediaPlayer.h>
Delegate this on .h file UIImagePickerControllerDelegate,UINavigationControllerDelegate
Then create one reference of mediaplayer like this
MPMoviePlayerController *moviePlayer;
Then go in .m file and add this code.
-(void)video
{
UIImagePickerController *imagepicker = [[UIImagePickerController alloc] init];
imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagepicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:imagepicker.sourceType];
imagepicker.delegate = self;
imagepicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
imagepicker.allowsImageEditing=NO;
[self presentModalViewController:imagepicker animated:YES];
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
videoData = [NSData dataWithContentsOfURL:videoURL];
[picker dismissModalViewControllerAnimated:YES];
}
call video function as per your requirement and record video and get that video url and data on didFinishPickingMediaWithInfo method.
i hope this code useful for you .

Related

IOS 10 UIImagePickerController Delegate Not Being Called

I have setup the following to select an image whilst using an IPad. The problem is that the delegate never seems to get called. I've placed breakpoints in but they are never activated.
.H
#interface HomeViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
.M
- (IBAction)loadImage:(id)sender {
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePickerController.allowsEditing = NO;
self.imagePickerController.delegate = self;
[self presentViewController:self.imagePickerController animated:YES completion:nil];
}
// This method is called when an image has been chosen from the library or taken from the camera.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//You can retrieve the actual UIImage
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
//Or you can get the image url from AssetsLibrary
NSURL *path = [info valueForKey:UIImagePickerControllerReferenceURL];
[picker dismissViewControllerAnimated:YES completion:nil];
}
Can anyone see the issue?
Thanks
if you used Xcode8 to run the project, please check the project's info.plist, make sure there is a key for "Privacy Photo library usage".
your code is right, maybe the problem is the info.plist.
I had a similar issue and it turned out that the picker was being garbage collected as soon as the image was picked, so the delegate wasn't called.
I needed to ensure that a strong reference to the picker was made before presenting it.
Once that was done, it worked fine.

how do i return an NSString or NSUrl from my didFinishPickingMediaWithInfo?

Good day, I am trying to implement the UIImagePickerController inside my selectFile function. (followed this tutorial in appcoda) but code below is a bit tweaked now based on what i want
#implementation FileBrowser
-(void)selectFile{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];
NSString *myURL = [refURL absoluteString]; //not in tutorial, I'm trying to grab the url/path of the image here, with an intention of returning it to "callFileBrowser"
[picker dismissViewControllerAnimated:YES completion:NULL];
}
#end
Based on what i understood, my imagePickerController function is called when user selects an image. My question is how do i return(or get) the url instead? I have a C function on the same file (but outside #implemetation), this function calls my selectFile and is supposed to return the url/path of what the user has chosen.
char* callFileBrowser(){
[fileBrowser selectFile];
//return myURL here;
}
I hope i was able to explain everything properly. Any advice would greatly be appreciated. thanks.
I don't think it is possible with the current design. callFileBrowser() is called to pick a image, then immediately it is required to return a value. We don't know when user will be done picking, I suggest you to post a notification in didFinishPickingMediaWithInfo when the url is ready to notify other object who needs it.

UIImagePickerController stream type used to append .MOV?

What stream is employed in iOS7 by AVCaptureMovieFileOutput in a UIImagePickerController to append video frames from the camera to it's temporary .MOV file?
A .MOV file is created in a temporary location, and then further appended to by an underlying AVCaptureMovieFileOutput object, when a user is recording a video via a presented UIImagePickerController in iOS7.
I've attempted to use symbolic breakpoints and method swizzling in order to pinpoint one of the following (but with no success). It's possible I've missed the one stream type or class that is actually being used (or that my breakpoints are setup incorrectly):
NSWriteStream
CFWriteStream
subclassed NSStream
fstream
ofstream
ostream
iostream
NSFileHandle
posix file descriptor
AVAssetWriter
AVAssertExportSession
ALAssetClass
ALAssetLibrary
This is what I am using to present the UIImagePickerViewController to record video:
#import <MobileCoreServices/MobileCoreServices.h>
-(void)startPicker{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[picker setAllowsEditing:NO];
[picker setDelegate:self];
[picker setMediaTypes:#[(NSString*)kUTTypeMovie]];
[self presentViewController:picker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
if (info)
{
NSURL* fileURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(#"%#", fileURL.path);
}
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];
}
I really need the specific stream type and a way that I can prove for myself that it is being used by iOS7. Many thanks!
A way you can prove? I am not sure, but Apple favors m3u8 for streaming
https://developer.apple.com/library/ios/documentation/networkinginternet/conceptual/streamingmediaguide/DeployingHTTPLiveStreaming/DeployingHTTPLiveStreaming.html

App using UIImagePickerController freezes when selecting "Use Photo" after taking a photo

I'm working on a simple photo and video capture app right now. The app successfully allows the user to take a photo or video on a button press. However, as soon as you finish taking your photo or video, it gives 2 options: "Retake" and "Use Photo" or "Use Video", depending on which one you're using.
If the user taps "Retake" then it just let's them retake a new photo or video, but when the user taps "Use photo" or "Use video" the screen freezes.
If I exit the frozen app and go look in my camera roll, the photo I just took using the app has successfully been saved. So when you tap the "Use Photo" button it does successfully save to the camera roll despite the fact that the app screen freezes.
I was told by someone that "it freezes because it takes some time to save the photo and it is running on main thread. You can use the ALAssetLibrary to fix the freezing issue."
However, I am not familiar with ALAssetLibrary or the theory of why it would be helpful in this situation. I just skimmed through some of it's documentation and I am still lost.
Any help would be greatly appreciated.
Here is the code that I have so far:
ViewController.h:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
#property UIImagePickerController * pickerController;
-(IBAction)showCameraUI;
#end
ViewController.m:
#import "ViewController.h"
#import <MobileCoreServices/MobileCoreServices.h>
#interface ViewController () <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
//The above are the 2 delegates required for creating a media capture/camera app.
- (void)imagePickerController:pickerController didFinishPickingMediaWithInfo:(NSDictionary *)info;
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
NSLog(#"%ld", (long)UIImagePickerControllerSourceTypeCamera);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)showCameraUI{
UIImagePickerController * pickerController = [[UIImagePickerController alloc]init];
pickerController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerController.delegate = self;
[self presentViewController:pickerController animated:YES completion:nil];
}
- (void)imagePickerController:pickerController didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// saves the photo you just took
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);
}
}
- (void)imagePickerControllerDidCancel:pickerController
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#end

iPad UIImagePicker Problem !

iam trying import an image from photos library but when i press the import button program crashes and received SGIBART !! but my code works fine on iPhone why ?
here is my code :
.h :
#interface CameraViewController : UIViewController <UIImagePickerControllerDelegate ,UINavigationControllerDelegate> {
UIImagePickerController *ipc;
UIImageView * image1;
#property (.......................;
}
.m :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
image1.image = [[info objectForKey:UIImagePickerControllerOriginalImage]retain];
[[picker parentViewController]dismissModalViewControllerAnimated:YES];
[picker release];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[[picker parentViewController]dismissModalViewControllerAnimated:YES];
[picker release];
}
-(IBAction) importImage1 {
ipc = [[UIImagePickerController alloc]init];
ipc.delegate = self;
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:ipc animated:YES];
}
You're crashing because you're releasing picker, but you didn't retain it. You should remove the calls to [picker release].
You should switch to using accessors for all of your ivars. Accessors and dealloc are generally the only places you should retain or release your ivars. picker is not your ivar and you didn't create it, so you shouldn't be releasing it at all.
You should spend some time with the Memory Management Programming Guide. You can get the short version at Three Magic Words.
On the iPad iOS 3.2 a UIImagePickerController must be presented in a popover, not as a modal view.
check this out :
http://www.cocos2d-iphone.org/forum/topic/6108

Resources