AVCaptureDevice

2017-12-07  本文已影响34人  lltree

判断设备是否存在某一类型设备

- (BOOL)hasMediaType:(AVMediaType)mediaType;

获取捕获设备

目前iPhone 上只能获取以下设备:前、后摄像头 及麦克风

a 获取所有输入设备

b 根据设备类型获取该类设备
对于捕获设备来说只有 :摄像头(AVMediaTypeVideo)及麦克风(AVMediaTypeAudio),所以只有该值有效,其他值 返回nil

typedef NSString * AVMediaType NS_EXTENSIBLE_STRING_ENUM;

AVF_EXPORT AVMediaType const AVMediaTypeVideo                 NS_AVAILABLE(10_7, 4_0);
AVF_EXPORT AVMediaType const AVMediaTypeAudio                 NS_AVAILABLE(10_7, 4_0);
AVF_EXPORT AVMediaType const AVMediaTypeText                  NS_AVAILABLE(10_7, 4_0);
AVF_EXPORT AVMediaType const AVMediaTypeClosedCaption         NS_AVAILABLE(10_7, 4_0);
AVF_EXPORT AVMediaType const AVMediaTypeSubtitle              NS_AVAILABLE(10_7, 4_0);
AVF_EXPORT AVMediaType const AVMediaTypeTimecode              NS_AVAILABLE(10_7, 4_0);
AVF_EXPORT AVMediaType const AVMediaTypeMetadata              NS_AVAILABLE(10_8, 6_0);
AVF_EXPORT AVMediaType const AVMediaTypeMuxed                 NS_AVAILABLE(10_7, 4_0);

b 根据设备类型获取该类设备

NSArray *devices = [AVCaptureDevice devices]; //获取所有的输入设备

c 获取默认设备
该方法返回给定的媒体类型的默认设备当前可用的系统。例如,对于AVMediaTypeVideo,这个方法将返回内置的摄像头,主要是用于捕获和记录。媒体类型常量定义在AVMediaFormat.h
例如:摄像头有两个 如果需要获取肯定会有一个默认的

+ (nullable AVCaptureDevice *)defaultDeviceWithMediaType:(AVMediaType)mediaType
<__NSArrayM 0x1c0a552a0>(
<AVCaptureFigVideoDevice: 0x15709d240 [后置镜头][com.apple.avfoundation.avcapturedevice.built-in_video:0]>,
<AVCaptureFigVideoDevice: 0x15709db40 [前置相机][com.apple.avfoundation.avcapturedevice.built-in_video:1]>,
<AVCaptureFigAudioDevice: 0x1c0895bd0 [iPhone 麦克风][com.apple.avfoundation.avcapturedevice.built-in_audio:0]>
)

捕获设备在系统硬件上的位置

@property(nonatomic, readonly) AVCaptureDevicePosition position;
typedef NS_ENUM(NSInteger, AVCaptureDevicePosition) {
    AVCaptureDevicePositionUnspecified = 0,
    AVCaptureDevicePositionBack        = 1, //后置
    AVCaptureDevicePositionFront       = 2,  //前置
} NS_AVAILABLE(10_7, 4_0) __TVOS_PROHIBITED;

获取设备唯一ID

每一个设备都存在一个唯一ID

@property(nonatomic, readonly) NSString *modelID;  //二者相同
@property(nonatomic, readonly) NSString *uniqueID;

例如:其中uniqueID 为 com.apple.avfoundation.avcapturedevice.built-in_video:0 就为后置摄像头的唯一ID
<AVCaptureFigVideoDevice: 0x15709d240 [后置镜头][com.apple.avfoundation.avcapturedevice.built-in_video:0]>,
<AVCaptureFigVideoDevice: 0x15709db40 [前置相机][com.apple.avfoundation.avcapturedevice.built-in_video:1]>,
<AVCaptureFigAudioDevice: 0x1c0895bd0 [iPhone 麦克风][com.apple.avfoundation.avcapturedevice.built-in_audio:0]>
)

根据唯一ID 获取目标设备

+ (nullable AVCaptureDevice *)deviceWithUniqueID:(NSString *)deviceUniqueID;

获取设备所在位置名字

@property(nonatomic, readonly) NSString *localizedName;

例如:其中localizedName 为 "后置镜头" “前置相机”

<AVCaptureFigVideoDevice: 0x15709d240 [后置镜头][com.apple.avfoundation.avcapturedevice.built-in_video:0]>,
<AVCaptureFigVideoDevice: 0x15709db40 [前置相机][com.apple.avfoundation.avcapturedevice.built-in_video:1]>,
<AVCaptureFigAudioDevice: 0x1c0895bd0 [iPhone 麦克风][com.apple.avfoundation.avcapturedevice.built-in_audio:0]>
)

上一篇下一篇

猜你喜欢

热点阅读