Camera freeze
Opened this issue · 11 comments
Hello, great code and App, easy to understand and to make changes. I just added a selfie flash to your code and works grate for me, i can help you with that if you need, by the way. I tried to use the app when i make a call and the screen got freeze, i don't know why but if i change the SessionPreset to AVCaptureSessionPresetPhoto works fine, but i can't make videos. Do you know why the screen freeze when i use the AVCaptureSessionPresetHigh and i open the app when im calling?
I notice that i can keep the AVCaptureSessionPresetHigh and change the videoEnable:NO on this line:
[[LLSimpleCamera alloc] initWithQuality:AVCaptureSessionPresetHigh position:LLCameraPositionRear videoEnabled:NO];
and it will work but i can take videos... So debuging i see that if i turn it ON the problems appears on this line:
[self.session addOutput:_movieFileOutput];
I not sure if i was clear, if you need more info please msg me back.
Hi,
I have the same issue any advice for this case please.
If you want to record videos you need set videoEnabled = YES
and restart the camera. This will recreate the session allowing you to record the video. I know it will work because I created the pull request for that (which was accepted on version 5.0) =]
Here is a snippet from my CameraViewController
:
private var videoEnabled: Bool {
get {
return camera.videoEnabled
}
set(enabled) {
camera.videoEnabled = enabled
camera.stop()
camera.start()
}
}
@leonereveel Thanks for your answer but I try it, it's still freeze
@leonereveel i am using version 5.0 but still i am facing same issue. Please suggest me how can i solve this issue. Thanks
I tried to use the app when i make a call and the screen got freeze, i don't know why but if i change the SessionPreset to AVCaptureSessionPresetPhoto works fine, but i can't make videos. Do you know why the screen freeze when i use the AVCaptureSessionPresetHigh and i open the app when im calling?
It freezes because videomode get's the microphone. When your call starts, it captures the microphone from your app and your need to request for that again. The best way to do it is register your view controller to listen UIApplicationDidBecomeActiveNotification
and restart the camera when your app comes back.
@leonereveel I am getting issue while phone call is active. Please suggest me how to implement UIApplicationDidBecomeActiveNotification
in my code? Thanks
Your view controller should stop the camera when it's not visible and when your app is not active, and restart the camera when it becomes active or visible.
Here is the code, assuming you have a camera
variable inside your view controller. It is in Swift but you can translate to Objective-C quite easily.
class CameraViewController: UIViewController {
private let camera = LLSimpleCamera(quality:AVCaptureSessionPresetHigh,
position: LLCameraPositionRear,
videoEnabled: true)
override func viewDidLoad() {
super.viewDidLoad()
let nc = NSNotificationCenter.defaultCenter()
nc.addObserver(self,
selector: #selector(willResignActive),
name: UIApplicationWillResignActiveNotification,
object: nil)
nc.addObserver(self,
selector: #selector(didBecomeActive),
name: UIApplicationDidBecomeActiveNotification,
object: nil)
}
override func viewWillAppear(animated:Bool) {
super.viewWillAppear(animated)
camera.start()
}
override func viewWillDisappear(animated:Bool) {
super.viewWillDisappear(animated)
camera.stop()
}
func willResignActive() {
camera.stop()
}
func didBecomeActive() {
camera.start()
}
}
@leonereveel i have implement code as per your demo code . But still when i am in call and open the camera it's freeze. :( How can i solve this issue ? Thanks
I tested here and my camera is not freezing, event when I'm recording a video. I think you forgot set some callbacks or you're getting an error when they are executed.
My custom camera is reusable inside my app and I defined a delegate this way:
@objc protocol CameraDelegate: class {
func cameraDidFinishPickingPhoto(photo:UIImage?, error: NSError?)
func cameraDidFinishRecordingVideo(videoUrl videoUrl:NSURL?, previewImage:UIImage?, error:NSError?)
optional func cameraDidFinishWithError(error:NSError)
optional func cameraDidCancel()
}
Here is my code when some error happens:
camera.onDeviceChange = { [weak self] (_, device) in
self?.controls.update()
}
camera.onError = { [weak self] (_, error) in
self?.delegate?.cameraDidFinishWithError?(error)
}
I just show an alert in my delegate
implementation when some error happens.
@leonereveel If you don't have any problem then please share your whole demo code for this. Because i have implement same as you told But still getting same issue . Even i was implement that code in LLSimpleCamera demo code but getting same issue. So please help me. Thanks