zoukankan      html  css  js  c++  java
  • iOS 直播-闪光灯的使用

    iOS 直播-闪光灯的使用


    应用场景是这样的,最近公司决定做一款直播类的软件.
    在开发中就遇到了不曾使用过的硬件功能-闪光灯.
    这篇博客将简单介绍一下闪光灯的使用.

    //
    //  ViewController.m
    //  iOS torch-test
    //
    //  Created by caoxu on 16/6/7.
    //  Copyright © 2016年 caoxu. All rights reserved.
    //
    
    #import "ViewController.h"
    #import <AVFoundation/AVFoundation.h>
    
    @interface ViewController ()
    
    @property (nonatomic, strong) AVCaptureSession * session;
    @property (nonatomic, strong) AVCaptureDevice * device;
    @property (nonatomic, strong) NSTimer * timer;
    
    @end
    
    @implementation ViewController
    
    #pragma mark <setter and getter>
    -(AVCaptureSession *)session
    {
        if(_session == nil)
        {
            _session = [[AVCaptureSession alloc] init];
        }
        return _session;
    }
    
    -(AVCaptureDevice *)device
    {
        if(_device == nil)
        {
            _device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        }
        return _device;
    }
    
    #pragma mark <life cycle>
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        AVCaptureDeviceInput * input = [[AVCaptureDeviceInput alloc]initWithDevice:self.device error:nil];
        if ([self.session canAddInput:input]) {
            
            [self.session addInput:input];
            
        }
        
    
    }
    
    
    #pragma mark <method>
    - (IBAction)torchon:(id)sender {
        if([self.device hasTorch] && [self.device hasFlash])
        {
            if(self.device.torchMode == AVCaptureTorchModeOff)
            {
                [self.session beginConfiguration];
                [self.device lockForConfiguration:nil];
                [self.device setTorchMode:AVCaptureTorchModeOn];
                [self.device setFlashMode:AVCaptureFlashModeOn];
                [self.device unlockForConfiguration];
                [self.session commitConfiguration];
            }
        }
        
        [self.session startRunning];
        
    }
    - (IBAction)torchoff:(id)sender {
        
        [self.session beginConfiguration];
        [self.device lockForConfiguration:nil];
        
        if(self.device.torchMode == AVCaptureTorchModeOn)
        {
            [self.device setTorchMode:AVCaptureTorchModeOff];
            [self.device setFlashMode:AVCaptureFlashModeOff];
        }
        
        [self.device unlockForConfiguration];
        [self.session commitConfiguration];
        [self.session stopRunning];
        
    }
    
    
    @end
    
    
  • 相关阅读:
    【题解】CodeChef
    【题解】AT1984 Wide Swap(拓扑排序)
    【题解】CF917D Stranger Trees(prufer序列+二项式反演)
    【题解】UVA
    【题解】P3980 [NOI2008]志愿者招募(费用流求线性规划)
    【题解】AT2064 Many Easy Problems(转换+NTT)
    【题解】AT1983 BBQ Hard (格路)
    【总结】不同卷积如何来搞
    【瞎讲】 Cayley-Hamilton 常系数齐次线性递推式第n项的快速计算 (m=1e5,n=1e18)
    计算几何小结计算几何小结
  • 原文地址:https://www.cnblogs.com/xubaoaichiyu/p/5567333.html
Copyright © 2011-2022 走看看