• 视屏录制


    #import "ViewController.h"
    #import <AVFoundation/AVFoundation.h>
    
    @interface ViewController ()<AVCaptureFileOutputRecordingDelegate>
    
    @property(nonatomic ,strong) AVCaptureFileOutput * outPut;
    
    @property(nonatomic ,strong)AVCaptureSession * session;
    
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
    
        //创建输入设备
        
        AVCaptureDevice * device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        
          AVCaptureDeviceInput * inputVideo = [[AVCaptureDeviceInput alloc]initWithDevice:device error:nil];
        
        AVCaptureDevice * audio = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
        
        AVCaptureDeviceInput * inpoutAudio = [[AVCaptureDeviceInput alloc]initWithDevice:audio error:nil];
        
        //创建文件输出设备
    
         AVCaptureFileOutput * outPut =  [[AVCaptureFileOutput alloc]init];
        
        
        self.outPut = outPut;
        //创建会话(加工厂)
        
        AVCaptureSession * session = [[AVCaptureSession alloc]init];
        
        self.session = session;
        
        //判断设备时候能够添加, 可能设备损坏
        if ([session canAddInput:inpoutAudio]) {
            
            [session addInput:inpoutAudio];
            
        }
     
        if ([session canAddInput:inputVideo]) {
            
            [session addInput:inputVideo];
        }
        
        if ([session canAddOutput:outPut]) {
            
            [session addOutput:outPut];
        }
    
        //创建预览层
        
        AVCaptureVideoPreviewLayer * preViewLayer = [[AVCaptureVideoPreviewLayer alloc]init];
        
        //设置frame
        preViewLayer.frame = self.view.bounds;
    
        //插入到View上
        
        [self.view.layer insertSublayer:preViewLayer atIndex:0];
        
        //开始会话
        
        [session startRunning];
    
        
    }
    
    - (IBAction)recode:(id)sender {
        
        if ([self.outPut isRecording]) {
            
            [self.outPut stopRecording];
            
        }else{
            
            NSString * path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject]stringByAppendingPathComponent:@"录制视屏.MP4"];
            
            
            [self.outPut startRecordingToOutputFileURL:[NSURL fileURLWithPath:path] recordingDelegate:self];
            
        }
        
        
        
        
    }
    

      

  • 相关阅读:
    Scala(四)流程控制
    Scala(九)异常
    Idea中安装翻译插件
    hiveserver2启动卡住问题解决方案
    Scala(十)隐式转换
    Scala(七)集合
    Scala(六)面向对象
    Scala(八)模式匹配
    SharePoint 2010 文档库添加文件icon
    Windows Server 2008 r2 在Hyperv里搭建SharePoint 2010开发环境
  • 原文地址:https://www.cnblogs.com/yuwei0911/p/5448910.html
Copyright © 2020-2023  润新知