https://github.com/shaojiankui/jkscreenrecorder
JKScreenRecorder(屏幕录制),use RPScreenRecorder of ReplayKit.framework supports iOS9 and later, use AVAssetWriter of AVFoundation.framework supports iOS8
https://github.com/shaojiankui/jkscreenrecorder
apprecorder avfoundation jkscreenrecorder replaykit screenrecord
Last synced: 11 months ago
JSON representation
JKScreenRecorder(屏幕录制),use RPScreenRecorder of ReplayKit.framework supports iOS9 and later, use AVAssetWriter of AVFoundation.framework supports iOS8
- Host: GitHub
- URL: https://github.com/shaojiankui/jkscreenrecorder
- Owner: shaojiankui
- License: mit
- Created: 2016-12-29T03:23:04.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-05T06:17:19.000Z (over 9 years ago)
- Last Synced: 2025-04-05T00:37:02.971Z (about 1 year ago)
- Topics: apprecorder, avfoundation, jkscreenrecorder, replaykit, screenrecord
- Language: Objective-C
- Size: 157 KB
- Stars: 32
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JKScreenRecorder
JKScreenRecorder(屏幕录制),use RPScreenRecorder of ReplayKit.framework supports iOS9 and later, use AVAssetWriter of AVFoundation.framework supports iOS8
应用内屏幕录制功能,iOS9之后使用原生ReplayKit进行录制,iOS8及以后使用截图方式保存视频.
## 使用方法
开始录制
```
- (IBAction)startTouched:(id)sender {
_sreenRecorder = [[JKScreenRecorder alloc]init];
//不区分系统版本 直接使用截图合成视频
//[_sreenRecorder startRecordingWithCapture];
//根据不同版本的系统SDK 使用不同的API 两种开始方法调用一种即可
[_sreenRecorder startRecordingWithHandler:^(NSError *error) {
}];
[_sreenRecorder screenRecording:^(NSTimeInterval duration) {
self.timeLabel.text = [@(duration) stringValue];
}];
}
```
结束录制
```
- (IBAction)stopTouched:(id)sender {
[_sreenRecorder stopRecordingWithHandler:^(UIViewController *previewViewController, NSString *videoPath, NSError *error) {
//videoPath非空为使用低版本截图方式保存视频 previewViewController为MPMoviePlayerViewController的实例
if (videoPath) {
MPMoviePlayerViewController *p = (MPMoviePlayerViewController*)previewViewController;
[p.moviePlayer prepareToPlay];
[p.moviePlayer play];
[self presentMoviePlayerViewControllerAnimated:p];
// 存入相册 注意要在info.plist中增加 Privacy - Photo Library Usage Description
// ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// [library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:videoPath]
// completionBlock:^(NSURL *assetURL, NSError *error) {
// if (error) {
// NSLog(@"Save video fail:%@",error);
// } else {
// NSLog(@"Save video succeed.");
// }
// }];
}else{
//videoPath空为使用ReplayKit.framework方式录制视频 previewViewController为RPPreviewViewController的实例
[self presentViewController:previewViewController animated:YES completion:^{
}];
}
}];
}
```
## 效果
