2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【iOS開発メモ】AVFoundationでキャプチャデバイスの検出

Last updated at Posted at 2018-10-22

AVCaptureDevice.DescoverySessionクラスを使用してiPhoneで使用可能なキャプチャデバイスを検出します。

使用した端末

iPhone SE(iOS 11)

コード

import UIKit
import AVFoundation

class ViewController: UIViewController {

    var device = AVCaptureDevice.DiscoverySession(
        deviceTypes: [
            AVCaptureDevice.DeviceType.builtInWideAngleCamera,
            AVCaptureDevice.DeviceType.builtInMicrophone,
            AVCaptureDevice.DeviceType.builtInDualCamera,
            AVCaptureDevice.DeviceType.builtInTelephotoCamera,
            AVCaptureDevice.DeviceType.builtInTrueDepthCamera
        ],
        mediaType: AVMediaType.video,
        position: AVCaptureDevice.Position.unspecified
    )

    override func viewDidLoad() {
        super.viewDidLoad()
        print(type(of: device.devices), device.devices)
    }
}

型推論があるのでAVCaptureDevice.DeviceTypeなどは省略可能です。
mediaTypeを変えてやればマイクなどのデバイスの検出も可能。

出力(見やすく編集してます)

Array<AVCaptureDevice> 
[<AVCaptureFigVideoDevice: 0x10160d8e0 [Back Camera][com.apple.avfoundation.avcapturedevice.built-in_video:0]>,
 <AVCaptureFigVideoDevice: 0x1016134d0 [Front Camera][com.apple.avfoundation.avcapturedevice.built-in_video:1]>]

これでAVCaptureDvice型のオブジェクトが取得できる。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?