Skip to content

Commit

Permalink
重构3
Browse files Browse the repository at this point in the history
  • Loading branch information
q651082931 committed Feb 2, 2018
1 parent 8570196 commit c3c2bf8
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
81136DAF20247FAB001B203C /* JLRecorderManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 81136DAE20247FAB001B203C /* JLRecorderManager.m */; };
817417982024098F002423D3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 817417972024098F002423D3 /* AppDelegate.m */; };
8174179B2024098F002423D3 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8174179A2024098F002423D3 /* ViewController.m */; };
8174179E2024098F002423D3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8174179C2024098F002423D3 /* Main.storyboard */; };
Expand All @@ -27,6 +28,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
81136DAD20247FAB001B203C /* JLRecorderManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JLRecorderManager.h; sourceTree = "<group>"; };
81136DAE20247FAB001B203C /* JLRecorderManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JLRecorderManager.m; sourceTree = "<group>"; };
817417932024098F002423D3 /* JLScreenRecordDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JLScreenRecordDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
817417962024098F002423D3 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
817417972024098F002423D3 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -124,6 +127,8 @@
817417AD20240F90002423D3 /* JLCaptureUtilities.m */,
817417AF20240F90002423D3 /* JLScreenRecorder.h */,
817417AE20240F90002423D3 /* JLScreenRecorder.m */,
81136DAD20247FAB001B203C /* JLRecorderManager.h */,
81136DAE20247FAB001B203C /* JLRecorderManager.m */,
);
path = JLScreenRecordKit;
sourceTree = "<group>";
Expand Down Expand Up @@ -203,6 +208,7 @@
buildActionMask = 2147483647;
files = (
817417BF2024128D002423D3 /* HiARCapture.m in Sources */,
81136DAF20247FAB001B203C /* JLRecorderManager.m in Sources */,
817417D520244A99002423D3 /* AGLKVertexAttribArrayBuffer.m in Sources */,
817417D320244A99002423D3 /* glViewController.m in Sources */,
8174179B2024098F002423D3 /* ViewController.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#import <CoreAudio/CoreAudioTypes.h>

@protocol JLAudioRecordDelegate<NSObject>
-(void)wavComplete;
//-(void)wavComplete;
@end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
static NSString * const JLAudio = @"JLAudio";
@interface JLAudioRecord()

@property (retain, nonatomic) AVAudioRecorder * audioRecorder;
@property (strong, nonatomic) AVAudioRecorder * audioRecorder;
@end

@implementation JLAudioRecord
Expand Down Expand Up @@ -56,17 +56,6 @@ - (void)clearAudioFile{
}
}

#pragma mark - 开始或结束
-(void)toRecordOrPause:(NSNotification*)sender
{
NSString* str=(NSString*)[sender object];
if ([str intValue]) {
[self startRecord];
}
else{
[self pauseRecord];
}
}

#pragma mark - 录音开始
-(void)startRecord{
Expand All @@ -84,13 +73,14 @@ -(void)pauseRecord{

#pragma mark - 录音结束
- (void)endRecord{

if (self.audioRecorder.isRecording||(!self.audioRecorder.isRecording&&_nowPause)) {
[self.audioRecorder stop];
self.audioRecorder = nil;

if ([self.delegate respondsToSelector:@selector(wavComplete)]) {
[self.delegate wavComplete];
}
// if ([self.delegate respondsToSelector:@selector(wavComplete)]) {
// [self.delegate wavComplete];
// }

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// JLRecorderManager.h
// JLScreenRecordDemo
//
// Created by 孙金亮 on 2018/2/2.
// Copyright © 2018年 hiscene. All rights reserved.
//

#import <Foundation/Foundation.h>


typedef void (^VideoCompletionBlock)(NSString * path);

@interface JLRecorderManager : NSObject
@property (nonatomic, readonly) BOOL isRecording;

@property(nonatomic,assign)NSInteger maxRecordTime;//最大录屏时间 defalut 60s
@property(nonatomic,assign)NSInteger minRecordTime;//最大录屏时间 defalut 60s
@property (strong, nonatomic) NSURL *videoURL;//视频文件目标目标地址,不设置也可以
@property(nonatomic,assign)int top_edge; //录屏范围上边距
@property(nonatomic,assign)int buttom_edge;//录屏范围下边距

+ (instancetype)sharedInstance;
- (BOOL)startRecording;
- (void)stopRecordingWithCompletion:(VideoCompletionBlock)completionBlock;
- (void)clear; //单例类必须主动清理
- (void)clearFile;//清理录制缓存文件;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
// JLRecorderManager.m
// JLScreenRecordDemo
//
// Created by 孙金亮 on 2018/2/2.
// Copyright © 2018年 hiscene. All rights reserved.
//

#import "JLRecorderManager.h"
#import "JLAudioRecord.h"
#import "JLScreenRecorder.h"
#import "JLCaptureUtilities.h"


@interface JLRecorderManager()

@property(nonatomic,strong) JLAudioRecord * audioRecord;
@property(nonatomic,copy) VideoCompletionBlock completionBlock;
@property(nonatomic,strong)JLScreenRecorder * screenRecord;

@end

@implementation JLRecorderManager



#pragma mark - initializers
static dispatch_once_t once;
static JLRecorderManager * sharedInstance;
+ (instancetype)sharedInstance {


dispatch_once(&once, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
- (void)clear{
once = 0;
sharedInstance = nil;

}

- (void)dealloc{

[self clearFile];

}
- (instancetype)init
{
self = [super init];
if (self) {

self.screenRecord = [[JLScreenRecorder alloc]init];
self.audioRecord = [[JLAudioRecord alloc]init];
[self.audioRecord prepareRecord];
}

return self;
}
- (void)clearFile{
[self.screenRecord clearFile];
[self.audioRecord clearAudioFile];

}
- (BOOL)startRecording
{

[self.audioRecord beginRecord];

return [self.screenRecord startRecording];


}

- (void)stopRecordingWithCompletion:(VideoCompletionBlock)completionBlock;
{
self.completionBlock = completionBlock;
[self.audioRecord endRecord];
__weak typeof(self) weakSelf = self;
[self.screenRecord stopRecordingWithCompletion:^(NSURL *vedioUrl) {

[JLCaptureUtilities mergeVideo:vedioUrl andAudio:weakSelf.audioRecord.recordFilePath andTarget:weakSelf andAction:@selector(mergedidFinish:WithError:)];
[weakSelf.screenRecord clearFile];

}];

}

- (void)mergedidFinish:(NSString *)videoPath WithError:(NSError *)error
{
dispatch_async(dispatch_get_main_queue(), ^{
if (self.completionBlock) self.completionBlock(videoPath);
});
}

- (void)setTop_edge:(int)top_edge{
_top_edge = top_edge;
self.screenRecord.top_edge = top_edge;


}
-(void)setButtom_edge:(int)buttom_edge{
_buttom_edge = buttom_edge;
self.screenRecord.buttom_edge = buttom_edge;


}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ typedef void (^VideoCompletionBlock)(NSString * path);
@property(nonatomic,assign)NSInteger maxRecordTime;//最大录屏时间 defalut 60s
@property(nonatomic,assign)NSInteger minRecordTime;//最大录屏时间 defalut 60s
@property (strong, nonatomic) NSURL *videoURL;//视频文件目标目标地址,不设置也可以
@property(nonatomic,assign)CGFloat top_edge;
@property(nonatomic,assign)CGFloat buttom_edge;
@property(nonatomic,assign)CGFloat top_edge; //录屏范围上边距
@property(nonatomic,assign)CGFloat buttom_edge;//录屏范围下边距



+ (instancetype)sharedInstance;
- (BOOL)startRecording;
- (void)stopRecordingWithCompletion:(VideoCompletionBlock)completionBlock;
- (void)stopRecordingWithCompletion:(void (^)(NSURL * vedioUrl))completionBlock;
+ (void)clear; //单例类必须主动清理
- (void)clearFile;//清理录制缓存文件;

Expand Down
Loading

0 comments on commit c3c2bf8

Please sign in to comment.