19
19
20
20
import ReplayKit
21
21
22
- public typealias PreviewControllerFinishedAction = ( activities: Set < String > ? ) -> ( )
23
- public typealias RecorderStoppedAction = ( ) -> ( )
24
-
25
22
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
+
28
30
public var controller : UIViewController ?
31
+ public var previewFinished : PreviewControllerFinishedAction ?
32
+ public var didStop : RecorderStoppedAction ?
33
+ public var microphoneEnabled = false
29
34
30
35
public override init ( ) {
31
36
super. init ( )
32
37
recorder = RPScreenRecorder . sharedRecorder ( )
33
38
}
34
39
35
40
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
42
42
if error != nil {
43
43
print ( " Start Recording Error: \( error? . localizedDescription) " )
44
44
}
@@ -48,50 +48,30 @@ public class ScreenRecorder: NSObject, RPPreviewViewControllerDelegate {
48
48
public func start( duration: Double ) {
49
49
preview = nil
50
50
51
- self . start ( )
51
+ start ( )
52
52
delay ( duration) {
53
53
self . stop ( )
54
54
}
55
55
}
56
56
57
- public var didStop : RecorderStoppedAction ?
58
57
59
58
public func stop( ) {
60
- self . recorder! . stopRecordingWithHandler { previewViewController, error in
59
+ recorder? . stopRecordingWithHandler { previewViewController, error in
61
60
self . preview = previewViewController
62
61
self . preview? . previewControllerDelegate = self
63
62
self . didStop ? ( )
64
63
}
65
64
}
66
65
67
66
public func showPreview( ) {
68
- guard controller != nil else {
69
- print ( " Recorder has no controller in which to present preview. " )
70
- return
71
- }
72
-
73
67
guard let p = preview else {
74
68
print ( " Recorder has no preview to show. " )
75
69
return
76
70
}
77
71
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 )
87
73
}
88
74
89
- internal func screenRecorder( screenRecorder: RPScreenRecorder , didStopRecordingWithError error: NSError , previewViewController: RPPreviewViewController ? ) {
90
- }
91
-
92
- public var previewFinished : PreviewControllerFinishedAction ?
93
-
94
- var activities : Set < String > ?
95
75
public func previewController( previewController: RPPreviewViewController , didFinishWithActivityTypes activityTypes: Set < String > ) {
96
76
self . activities = activityTypes
97
77
}
0 commit comments