I have quick question. I am using the following code to launch camera and record video on iOS 4.x devices, it works great. I want to use the same code on iPad 2 device as iPad 2 has video recording facility. Will it work? Can someone please guide me?
if ([types containsObject:(id)kUTTypeMovie])
{
UIImagePickerController *pickerController = [[[UIImagePickerController alloc] init] autorelease];
pickerController.delegate = self;
pickerController.videoQuality = appDelegate.settingsCtrler.quality;
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerController.showsCameraControls = YES;
pickerController.mediaTypes = [NSArray arrayWithObject:(id)kUTTypeMovie];
pickerController.videoMaximumDuration = maxDuration;
[appDelegate hideFloatingBar];
[self presentModalViewController:pickerController animated:YES];
}
Thank you in Advance!
If it builds on iOS 4.3 you should be OK - although I don't have an iPad2 to test it on. I would wrap the logic in a test though:
if([picker isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// Your code here.
}
so that it doesn't try and present a camera when one isn't available.
Related
I am developing app for iPad, in Landscape mode during taking a snapshot from camera a black preview appears.While , UIImagePickerController works properly for Portrait mode.Thanks in advance.
this is my piece of code -
-(UIImagePickerController *)imagePicker{
if(!imagePicker){
imagePicker = [[UIImagePickerController alloc]init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
}
return imagePicker;
}
[self presentViewController:self.imagePicker animated:YES completion:^{ }];
PS: Anybody knows about, "Contacts" default app of iOS device having this feature rotation of camera controls with respect to device orientation.Here, Camera preview looks fine for all orientation.Anybody knows its implementation.
if you are using Autolayout then you first Check for the co-ordinates and size of corresponding preview(UIimageview).
I am experiencing an issue when using the iPad Camera in iOS 8. I've seen some older questions and a thread on the Apple Developer Forums from during the beta but still haven't find a solution.
There seems to be two parts to this issue.
1) The camera itself rotates when the device orientation rotates, eg the world is on its side
2) When opening the camera in Landscape, the overlay does not appear. When opened in Portrait it is fine.
It is an app using iOS7 as the Base SDK, problem only occurs when running the app on a device that has been upgraded to iOS8. The app is not using storyboards, it is using nibs.
I'm hoping to push out a fix for this with Xcode 5.1.1 before moving onto the iOS8 specific fixes and using it as a Base SDK in the next version.
Here is my code to bring up the camera:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == YES) {
// Create Camera
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.showsCameraControls = NO;
// Set up custom controls view
[[NSBundle mainBundle] loadNibNamed:#"OverlayView" owner:self options:nil];
self.overlayView.frame = imagePicker.cameraOverlayView.frame;
imagePicker.cameraOverlayView = self.overlayView;
self.overlayView = nil;
// Show Camera
[self presentViewController:imagePicker animated:NO completion:nil];
[imagePicker release];
}
I have also tried
And the Layout of the Toolbar (sitting at the bottom) of the OverlayView:
If I change that to sit "at the top" it appears in both portrait and landscape! So it must have to do with the view/window/something size, though it's strange how its behaviour would change when the layout has stayed the same.
I have tried it with both showsCameraControls = YES and hashing out the OverlayView block, and problem #1 persists so it's not to do with the overlay at app.
I'm hoping someone has found an answer to this, it seems like quite a common problem.
Please let me know if you need any further details.
Edit 1: Fixed the Overlay (Issue #2)
It wasn't applying the orientation to the OverlayView, fixed it like this:
// Grab the window frame and adjust it for orientation - from http://stackoverflow.com/a/15707997/520902
UIView *rootView = [[[UIApplication sharedApplication] keyWindow]
rootViewController].view;
CGRect originalFrame = [[UIScreen mainScreen] bounds];
CGRect screenFrame = [rootView convertRect:originalFrame fromView:nil];
...
self.overlayView.frame = imagePicker.cameraOverlayView.frame;
I suspect that it's related to the camera not realising it's orientated too, will keep searching for a fix for Problem #1.
Edit 2: Update on Issue #1
Looks like the camera rotating might be an Apple issue. On iOS8 if you open up the Contacts app, edit a contact and choose 'Take Photo', the exact same issue occurs - in a default Apple app!
I still can't find a fix so I am just destroying and recreating the imagePicker on each orientation change for now, it's ugly but will suffice until Apple release a fix or a better solution pops up.
Apple fixed this problem in iOS 8.1.
I'v thought that dealing with UIPasteboard is easy but it turned out to be a time-consuming issue...
I want to store an UIImage in UIPasteboard and then paste this image in iMessage, WhatsApp, Gmail... and others.
That's my method where I use UIPasteboard
- (void) postClipboard
{
if ([[modelView currentView] isImage])
{
UIImage *image = [self readyImageLandscape:orientationLandscape];
[[UIPasteboard generalPasteboard] setImage:image];
}
}
It works on iPhone 3GS 5.1. I've tested it on Gmail and WhatsApp
Then I modified the method to
- (void) postClipboard
{
if ([[modelView currentView] isImage])
{
UIImage *image = [self readyImageLandscape:orientationLandscape];
[[UIPasteboard generalPasteboard] setImage:image];
[[UIPasteboard generalPasteboard] setPersistent:YES];
}
}
Still works on iPhone 3GS 5.1.
But my employer says that it doesn't work on iPhone 4S 6.0 neither in WhatsApp nor in any other application.
Am I doing all wrong or there should be another approach to make it work on iPhone 4S 6.0?
See this answer: https://stackoverflow.com/a/12613632/830946
Looks like that code will work with a single image, but not with multiple.
How can I let the user see the front facing camera, but prevent them from being able to take a picture, video, or switch to the rear camera on the iPhone 4/4s and/or the iPod Touch 4?
cameraPicker = [[UIImagePickerController alloc] init];
....
cameraPicker.showsCameraControls = NO;
cameraPicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
You can use AVFoundation framework to open camera.
Try this sample code https://developer.apple.com/library/ios/#samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112 .
I'm developing on iOS SDK 4.3.
I have an horizontally-scrolling paged gallery that can display images or videos from a remote feed. For the paged views I'm using the publicly available ATPagingView: pages are reused similarly to TableViewCells. But for the videos I'm using a single MPMoviePlayerController, whose .view property I assign to the several pages as a subview (I know, I know...):
moviePlayerController = [[MPMoviePlayerController alloc] init];
moviePlayerController.repeatMode = MPMovieRepeatModeNone;
moviePlayerController.controlStyle = MPMovieControlStyleEmbedded;
moviePlayerController.shouldAutoplay = false;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieLoadStateChangeAction:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
You can see I've registered for MoviePlayer event LoadState notifications.
When a new page goes onscreen, I start loading a video if needed:
- (void)currentPageDidChangeInPagingView:(ATPagingView *)pagingView
{
if (pagingView.currentPageIndex < 0)
return;
NSLog(#"currentPageDidChangeInPagingView");
GalleryPageView *currentPage = (GalleryPageView *)[pagingView viewForPageAtIndex:pagingView.currentPageIndex];
if (![currentPage.gestureRecognizers count]) {
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(resetZoom)];
recognizer.numberOfTapsRequired = 2;
[currentPage.zoomView addGestureRecognizer:recognizer];
recognizer.delegate = self;
[recognizer release];
}
moviePlayButton.hidden = YES;
[activityView stopAnimating];
FeedItem *feedItem = (FeedItem *)[dataRoot objectAtIndex:pagingView.currentPageIndex];
if (feedItem.contentType == FeedContentTypeMovie) {
moviePlayerController.contentURL = [NSURL URLWithString:feedItem.movieUrl];
[moviePlayerController prepareToPlay];
[activityView startAnimating];
}
Now, IFF the first page contains a video, even after I call moviePlayerController.prepareToPlay, it doesn't load: no loadState event is fired. Following pages instead work as expected.
I've tried to pre-load a fixed video on MPlayerController initialization, but in that case the fixed video is correctly loaded (MPMovieLoadState == 3), while video on first page causes a change to MPMovieLoadStateUnknown.
The movie URL is correct.
When I scroll back from page 2 to page 1, first video is loaded (MPMovieLoadState == 3), but it doesn't show.
What do you suggest investigating? Is the shared-view architecture so horrible? It works for the following pages, after all. Is there any known weird behavior by prepareToPlay? For example, is it possible MPC gets angry if the view is "mistreated" by anyone, and then it refuses to load stuff? How else would you explain MPMovieLoadStateUnknown? I'm pretty sure there is no other ghost instance of MPC messing around (I've read it could be a problem).
Thank you and sorry for the long post.
I had to end up using AVPlayer because of something very similar to this in my code.
I had the same problem. In iOS7 this does not happen, but in iOS 6 loadState is 3, which is not contemplated in:
enum {
MPMovieLoadStateUnknown = 0,
MPMovieLoadStatePlayable = 1 << 0,
MPMovieLoadStatePlaythroughOK = 1 << 1, // Playback will be automatically started in this state when shouldAutoplay is YES
MPMovieLoadStateStalled = 1 << 2, // Playback will be automatically paused in this state, if started
};
typedef NSInteger MPMovieLoadState;
I had autoplay set to NO and use prepareToPlay waiting for the notifications to play, so when MPMoviePlayerLoadStateDidChangeNotification is received, before playing, I check the loadState like this:
if (self.moviePlayerC.loadState & MPMovieLoadStatePlayable || self.moviePlayerC.loadState & MPMovieLoadStatePlaythroughOK)
Maybe in iOS6 loadState is a bitWise value that can contains several states at the same time.