Skip to content

Commit 657d8dd

Browse files
committed
Updates with fixes per @Aleph7 comments
1 parent 8b6e7a5 commit 657d8dd

File tree

1 file changed

+14
-34
lines changed

1 file changed

+14
-34
lines changed

Diff for: C4/UI/ScreenRecorder.swift

+14-34
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@
1919

2020
import ReplayKit
2121

22-
public typealias PreviewControllerFinishedAction = (activities: Set<String>?) -> ()
23-
public typealias RecorderStoppedAction = () -> ()
24-
2522
public class ScreenRecorder: NSObject, RPPreviewViewControllerDelegate {
26-
internal var recorder: RPScreenRecorder?
27-
public var preview: RPPreviewViewController?
23+
public typealias PreviewControllerFinishedAction = (activities: Set<String>?) -> ()
24+
public typealias RecorderStoppedAction = () -> ()
25+
26+
var recorder: RPScreenRecorder?
27+
var preview: RPPreviewViewController?
28+
var activities: Set<String>?
29+
2830
public var controller: UIViewController?
31+
public var previewFinished: PreviewControllerFinishedAction?
32+
public var didStop: RecorderStoppedAction?
33+
public var microphoneEnabled = false
2934

3035
public override init() {
3136
super.init()
3237
recorder = RPScreenRecorder.sharedRecorder()
3338
}
3439

3540
public func start() {
36-
guard recorder != nil else {
37-
print("Recorder was not initialized")
38-
return
39-
}
40-
41-
recorder!.startRecordingWithMicrophoneEnabled(false) { error in
41+
recorder?.startRecordingWithMicrophoneEnabled(microphoneEnabled) { error in
4242
if error != nil {
4343
print("Start Recording Error: \(error?.localizedDescription)")
4444
}
@@ -48,50 +48,30 @@ public class ScreenRecorder: NSObject, RPPreviewViewControllerDelegate {
4848
public func start(duration: Double) {
4949
preview = nil
5050

51-
self.start()
51+
start()
5252
delay(duration) {
5353
self.stop()
5454
}
5555
}
5656

57-
public var didStop: RecorderStoppedAction?
5857

5958
public func stop() {
60-
self.recorder!.stopRecordingWithHandler { previewViewController, error in
59+
recorder?.stopRecordingWithHandler { previewViewController, error in
6160
self.preview = previewViewController
6261
self.preview?.previewControllerDelegate = self
6362
self.didStop?()
6463
}
6564
}
6665

6766
public func showPreview() {
68-
guard controller != nil else {
69-
print("Recorder has no controller in which to present preview.")
70-
return
71-
}
72-
7367
guard let p = preview else {
7468
print("Recorder has no preview to show.")
7569
return
7670
}
7771

78-
self.controller?.presentViewController(p, animated: true, completion: nil)
79-
}
80-
81-
public func presentPreview(viewController: UIViewController) {
82-
guard preview != nil else {
83-
print("PreviewRecorder has no movie to preview.")
84-
return
85-
}
86-
viewController.presentViewController(self.preview!, animated: true, completion: nil)
72+
controller?.presentViewController(p, animated: true, completion: nil)
8773
}
8874

89-
internal func screenRecorder(screenRecorder: RPScreenRecorder, didStopRecordingWithError error: NSError, previewViewController: RPPreviewViewController?) {
90-
}
91-
92-
public var previewFinished: PreviewControllerFinishedAction?
93-
94-
var activities: Set<String>?
9575
public func previewController(previewController: RPPreviewViewController, didFinishWithActivityTypes activityTypes: Set<String>) {
9676
self.activities = activityTypes
9777
}

0 commit comments

Comments
 (0)