Skip to content

Adds an object that captures the screen using ReplayKit. #612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

traviskirton
Copy link
Collaborator

No description provided.

@alejandro-isaza
Copy link
Member

What about this

public class ScreenRecorder: NSObject, RPPreviewViewControllerDelegate {
    public typealias PreviewControllerFinishedAction = (activities: Set<String>?) -> ()
    public typealias RecorderStoppedAction = () -> ()

    var recorder = RPScreenRecorder.sharedRecorder()
    var preview: RPPreviewViewController?
    var activities: Set<String>?

    public var previewFinishedAction: PreviewControllerFinishedAction?
    public var recorderStoppedAction: RecorderStoppedAction?
    public var enableMicrophone = false

    public func start() {
        preview = nil
        recorder.startRecordingWithMicrophoneEnabled(enableMicrophone) { error in
            if error != nil {
                print("Start Recording Error: \(error?.localizedDescription)")
            }
        }
    }

    public func start(duration: Double) {
        start()
        delay(duration) {
            self.stop()
        }
    }


    public func stop() {
        recorder.stopRecordingWithHandler { previewViewController, error in
            self.preview = previewViewController
            self.preview?.previewControllerDelegate = self
            self.recorderStoppedAction?()
        }
    }

    public func showPreviewInController(controller: UIViewController) {
        guard let p = preview else {
            print("Recorder has no preview to show.")
            return
        }

        controller.presentViewController(p, animated: true, completion: nil)
    }

    public func previewController(previewController: RPPreviewViewController, didFinishWithActivityTypes activityTypes: Set<String>) {
        activities = activityTypes
    }

    public func previewControllerDidFinish(previewController: RPPreviewViewController) {
        previewFinishedAction?(activities: activities)
        preview?.parentViewController?.dismissViewControllerAnimated(true, completion: nil)
    }
}

@traviskirton
Copy link
Collaborator Author

Looks good. Only change would be to rename recorderStoppedAction to:

recordingEndedAction

I'm not a fan of:

recorder.recorder...

Nice trick with the parentViewController

@alejandro-isaza alejandro-isaza deleted the ScreenRecorder branch February 4, 2016 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants