初次尝试ios插件开发 & ReplayKit相关

昨天WonderParade把Ocean Adventure全部WFC了,然后想到录屏的时候,想起之前研究过的Quicktime录屏,在想能不能设备上录制

google之后搜到了ReplayKit,看起来非常简单的样子

最初尝试直接cycript执行,载入Framework之后虽然可以调用到开始和停止录制,但是因为cycript里的函数不是objc的方法,所以没办法搞回调

于是找了示例项目,粗略编了一个MS插件,作用仅仅就是声明一个ReplayKitObj类,代替调用开始/停止录制

毕竟也不熟练,怼了一阵搞出来一个能工作的版本,但是真正搞出来之后发现,ReplayKit录制质量特别渣……

基本上来讲,qt录制质量是100的话,airplay录制大概是85,rk就是60-70的样子…而且音频只录制了一个声道,这是最骚的

录制样品

ReplayKitObj.zip

//
//  ReplayKitObj.mm
//  ReplayKitObj
//
//  Created by ester on 2017/12/12.
//  Copyright (c) 2017年 __MyCompanyName__. All rights reserved.
//

// CaptainHook by Ryan Petrich
// see https://github.com/rpetrich/CaptainHook/

#if TARGET_OS_SIMULATOR
#error Do not support the simulator, please use the real iPhone Device.
#endif

#import <Foundation/Foundation.h>

// Objective-C runtime hooking using CaptainHook:
//   1. declare class using CHDeclareClass()
//   2. load class using CHLoadClass() or CHLoadLateClass() in CHConstructor
//   3. hook method using CHOptimizedMethod()
//   4. register hook using CHHook() in CHConstructor
//   5. (optionally) call old method using CHSuper()

#import <ReplayKit/ReplayKit.h>


@interface ReplayKitObj : UIViewController
//@interface ReplayKitObj : NSObject<RPPreviewViewControllerDelegate, RPScreenRecorderDelegate>
//@interface ReplayKitObj : UIViewController<RPPreviewViewControllerDelegate, RPScreenRecorderDelegate>

//-(void)startRec;
//-(void)stopRec;
//- (void)previewControllerDidFinish;
@end
//@interface ReplayKitObj () <RPPreviewViewControllerDelegate>
//@end

@implementation ReplayKitObj

+(void)startRec{
    
    NSLog(@"enter");
    
    
    
    
    //UIViewController* rootController = [UIApplication sharedApplication].keyWindow.rootViewController;
    
    RPScreenRecorder* recorder = RPScreenRecorder.sharedRecorder;
    
    
    [recorder startRecordingWithMicrophoneEnabled:false handler:^(NSError * error) {
        if(error != nil) {
            NSString* desc = error.description;
            NSLog(@"%@", desc);
            return;
        }
    }];
    
}

+(void)stopRec{
    
    NSLog(@"enter");
    
    [[RPScreenRecorder sharedRecorder] stopRecordingWithHandler:^(RPPreviewViewController * _Nullable previewViewController, NSError * _Nullable error){
        NSLog(@"EEEEE");
        if(error){
            NSLog(@"fialed to stop recording, %@", error);
            
        }else if(previewViewController != nil){
            NSLog(@"finish");
            
            previewViewController.previewControllerDelegate = self;
            
            UIViewController *rootController = [UIApplication sharedApplication].keyWindow.rootViewController;
            [rootController presentViewController:previewViewController animated:YES completion:nil];
            
        }
        
    }];
    
    NSLog(@"end");
    
}

+(void)previewControllerDidFinish:(RPPreviewViewController *)previewController {
    NSLog(@"previewControllerDidFinish");
    [[UIApplication sharedApplication].keyWindow.rootViewController dismissViewControllerAnimated:YES completion:nil];
}

+(void)previewController:(RPPreviewViewController *)previewController didFinishWithActivityTypes:(NSSet <NSString *>*)activityTypes {
	NSLog(@"activity - %@",activityTypes);
}

@end


总之,本来还在想要不要开发一个完整插件出来,但这么差的录制质量,还是算了

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax