rFlex / SCRecorder

iOS camera engine with Vine-like tap to record, animatable filters, slow motion, segments editing
Apache License 2.0
3.06k stars 583 forks source link

Recording/Photo Button like Snapchat #278

Closed janselv closed 8 years ago

janselv commented 8 years ago

I want to record/take photos using the same button like Snapchat does, photos on button tap, videos on holding, the problem is that trying to set the captureSessionPreset to photo before taking the photo takes to long and when button is tapped there is a delay to the photo be taken. after the photo is taken I restore to video capture preset since I want both video and photos be handled by the same button. What am I doing wrong ? There is a better way to do it ?

  recorder.captureSessionPreset = AVCaptureSessionPresetPhoto

    recorder.capturePhoto {
        error, image in
        error >>- { $0.tryHandle() }

        self.photo = image
        self.showPhoto(image)

        // restore the video capture preset

        dispatch_async(gcdQueue(.Initiated)){
            [weak self] in

            if let sSelf = self{
                sSelf.recorder.captureSessionPreset = AVCaptureSessionPresetHigh
            }
        }
    }
victorcampeanu commented 8 years ago

solved? pls give some details

mitchellporter commented 8 years ago

@janselr curious what you ended up using?

@victorcampeanu right now I don't change the captureSessionPreset I just use SCRecorder's capturePhoto method.

janselv commented 8 years ago

@victorcampeanu the question I tried to answer was how can I use the same recorder to take both photos & videos without the pain of the time took to reconfigure the recorder due on preset switching?. It turns out that leaving the preset to AVCaptureSessionPresetHigh worked for me in both scenarios. the final settings on the recorder that I'm using is this.

        recorder = SCRecorder()
        recorder.captureSessionPreset = AVCaptureSessionPresetHigh
        recorder.flashMode = .Auto
        recorder.initializeSessionLazily = false
        recorder.delegate = self
        recorder.autoSetVideoOrientation = true
        recorder.videoConfiguration.size = ...
        recorder.maxRecordDuration = ...

Relative to the coordination of the action to take on the button, I set a tap and long press gestures on it and responded to each one when performed, either calling capturePhoto or record.