How can I tell when UIImagePickerController is done switching cameras? - ios

I am encountering an issue where if I try to take a picture with UIImagePickerController immediately after switching the cameraDevice from back to front camera or vice versa I get an error:
UIImagePickerController: ignoring request to take picture; camera is changing modes.
I have tried subscribing to the AVCaptureSession* events from NSNotificationCenter, but none of the capture session ready notifications are fired when the camera device changes. Is there a way to determine that the camera is ready again after switching cameras in UIImagePickerController?

Check out the code below:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(cameraIsReady:)
AVCaptureSessionInterruptionEndedNotification object:nil];
You would use this to kick off the code you want once the cameras are ready.
If you post your code, I can come back and edit in further help for you.

Related

Fixed video capture orientation for RTCMTLVideoView webrtc

I have an iOS app that only supports portrait when rotating the device the video captured by the RTCMTLVideoView rotates to landscape orientation, even when the rest of the UI stays in portrait.
So far the only solution that I found is to listen for the UIDeviceOrientationDidChangeNotification notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
and disabling it
- (void)orientationChanged:(NSNotification *)notification{
NSLog(#"orientation changed");
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
Is there any way to prevent this behaviour and keep it locked to portrait without this ugly workaround?
The problem in my case was that the video captured with the front camera was no mirrored.
I fixed the issue flipping the RTCMTLVideoView
self.myRTCMTLVideoView.transform = CGAffineTransformMakeScale(-1.0, 1.0)
The answer assumes usage of the latest stable M70 branch of WebRTC at the moment, as it's a moving target and API of its internal classes changes frequently.
Looks like RTCMTLVideoView is still work in progress and doesn't handle all scenarios appropriately. It has a rotationOverride property, but no documentation or example on how to use it. There is a similar question on Google Groups, which hasn't yet received attention, I encourage you to participate in discussion there, so WebRTC developers would know about that issue relevancy and made actions to fix it.
In the meantime, I suggest to switch to RTCEAGLVideoView which should work fine in that case.

Change Orientation for Youtube Videos ONLY

I currently have my iPhone application orientation set to Portrait only and was wondering if it were possible to change the orientation of a Youtube video, since it comes up in its own modal view controller?
I have a UIWebView that has a youtube video in there and when clicking it, it brings up the youtube/apple media player in a modal view controller. Is it possible to only change the orientation of this video player, to three orientations, and then reset it back to portrait once it is done?
I noticed in another post that these two help see if the movie player is active and inactive but I have not figured out how to change the orientation and then reset it. Any guidance and help is appreciated in advance. Thanks!
Code that is used to check for Movie Player start/finish
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeStarted:) name:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeFinished:) name:#"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];
Does anyone know how to control or grab the UIMoviePlayerController? Maybe there is someway to intercept it and control its orientation.

How to take a photo on the volume-up event when using UIImagePickerController with custom camera controls?

In iOS 5, the volume-up button will now take a photo in the camera app, and on a UIImagePickerController instance where .showsCameraControlls == YES. Happy days.
However, when I set showsCameraControlls to NO, and supply my own (which in turn triggers takePicture method), the volume-up button will no longer work. How can I detect the volume event while the UIImagePickerController is showing?
The old way to detect volume changes was like so:
AudioSessionSetActive(true);
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(volumeChanged:)
name:#"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
I added this code to my application delegate. Strangely volumeChanged: is not triggered until after I show the UIImagePickerController for the first time. More importantly, it isn't triggered while the UIImagePickerController is visible (nor is the usual volume HUD shown), I guess since Apple disabled it & hijacked the event.
So once again, is there any way to detect the volume-up button event, while the UIImagePickerController is being displayed, when using custom camera controls, for the purpose of taking a photo?
If you're wondering why I need to use custom camera controls, it is because I want the ability to take multiple photos, which the standard camera controls do not allow.
On iOS 8 you can add an observer to the notification _UIApplicationVolumeUpButtonDownNotification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(volumeChanged:)
name:#"_UIApplicationVolumeUpButtonDownNotification"
object:nil];
If you are using UIImagePickerController, I was able to capture the event and use it to call TakePicture with a custom view.
On top of that, UIImagePickerController ensures that pressing volume up won't change the volume.
I'm not sure if Apple would approve an app listening to that notification; this seems to be the cleanest approach.
Try using the AVCapture APIs instead of UIImagePicker. Here's a tutorial:
http://www.musicalgeometry.com/?p=1273
It's a lot lower level and it's harder to use, but it shouldn't block the volume controls.
You might also want to try a trick like playing a silent audio file to enable the volume controls during image capture.
Update: I also found this tutorial on using the volume button for camera shutter:
http://ios.biomsoft.com/2011/12/07/taking-control-of-the-volume-buttons-on-ios-like-camera/

Is it possible to detect if a user takes a screenshot in iOS? [duplicate]

Is there a notification or other mechanism of being informed that the user is taking a screenshot with the home/power buttons?
I've seen threads about wanting to disable the taking of screenshots, but that's not what I'm looking to do.
I have a photographer client who's concerned that his works will be copied by means of users taking screenshots and I thought that if there was an opportunity to put a watermark across the image before the screenshot was taken, that would allay his fears.
The PictureWasTakenNotification Darwin notification will be sent when the user takes a screenshot. However, this is sent after the screenshot is taken.
(No notifications will be sent before the screenshot was taken.)
Here's a way which might work, although it will totally go against user interface guidelines I'm sure. If you force the user to have their finger on the screen for the image to show then I don't think they can create screenshots. Because as soon as you press the home+lock keys to actually take the screenshot, the screen seems to behave as if there are no fingers touching it. Try taking a screenshot while moving between home screens to see what I mean.
Not a perfect solution by any means but you may be able to work it into your app design if you're really clever without it detracting too much from the user experience (a tough challenge though!). Nevertheless, I believe this may allow you to display artwork/photos without allowing users to take screenshots.
Since iOS 7 the UIApplicationUserDidTakeScreenshotNotification exists. So doing something like this should detect the screenshots:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(userDidTakeScreenshot) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
}
- (void)userDidTakeScreenshot {
// Screenshot taken, act accordingly.
}
Finally, don't forget to remove the observer:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationUserDidTakeScreenshotNotification object:nil];
}
What's really needed is a notification that is sent before the actual screen capture happens. A delegate method or some other means of giving the app a screenshotting-in-flight opportunity to redraw your content before the grab happens.
And there isn't one.

How to know when Youtube player/plugin on iPad goes fullscreen?

Is there any way to know when the Youtube player/plugin on iPad goes fullscreen?
I have a UIWebview being displayed inside a Modal view controller that contains a Youtube video. If the user choose to view the Youtube video in fullscreen mode, it's displayed in fullscreen (naturally), but behind the UIWebview's modal view.
I'd like to know if some Notification or Delegate message is sent when the video starts to play in fullscreen mode, so that I would be able dismiss my modal view controller (or bring the Youtube fullscreen video to front in some way).
Thanks in advance.
I think the best way is to :
1°) Know it by JS (because it's inside the UIWebView), like adding a click() event on the youtube object.
2°) Do an JS action and caught it with the UIWebViewDelegate
Maybe there is a better solution.
Good Luck !
For anyone interested, I found an alternative workaround for this.
I created a custom UIView inherited class for the view containing the webview. Responding to the (BOOL)pointInside event, if the touch event took place within coordinates of YouTube's 'fullscreen' button on the bottom right, I passed a notification to trigger a dismissal of the modalviewcontroller.
A little ugly, but it works for me!
As per #prabhu-natarajan
in ViewDidLoad add the following code
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(VideoExitFullScreen:) name:#"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(VideoEnterFullScreen:) name:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
The following methods are for showing the message/functions for respective process of entering/exiting to/from full screen
- (void)VideoExitFullScreen:(id)sender{
// Your respective content/function for Exit from full screen
}
- (void)VideoEnterFullScreen:(id)sender{
// Your respective content/function for Enter to full screen
}
From : This link

Resources