---
lang: ja
path: cookbook/ios-sdk/select-devices
labels: クックブック/iOS SDK/カメラの選択
metaTitle: カメラの選択 | iOS SDK｜ クックブック ｜ SkyWay（スカイウェイ）
---

# カメラの選択

ビデオ通話を行う場合、カメラから取得した映像を送信できます。

このとき、複数のカメラの中からキャプチャするカメラを選択することができます。

SkyWay iOS SDKでは、カメラ入力に関するAPIを[`CameraVideoSource`](https://ios-sdk.api-reference.skyway.ntt.com/core/Classes/SKWCameraVideoSource.html)で提供しています。

## カメラを選択して映像をキャプチャする

### 使用可能なカメラの一覧を取得する

使用可能なカメラの一覧を取得するためには、まず[`CameraVideoSource.supportedCameras()`](https://ios-sdk.api-reference.skyway.ntt.com/core/Classes/SKWCameraVideoSource.html#/c:objc(cs)SKWCameraVideoSource(cm)supportedCameras)を利用します。

```swift
let cameras = CameraVideoSource.supportedCameras()
```
### カメラを選択する

使用可能なカメラを取得したら、次に使用するカメラを選択します。
`supportedCameras`で返却される配列の要素から、[`AVDevice.Position`](https://developer.apple.com/documentation/avfoundation/avcapturedevice/position-swift.enum)でカメラの位置をチェックします。

```swift
let camera = cameras.first(where: { $0.position == .front })
```

なお、これらの処理は以下のように1行で書くこともできます。

```swift
let camera = CameraVideoSource.supportedCameras().first(where: { $0.position == .front })
```

### カメラから映像をキャプチャをする

カメラが正常に取得できていることを確認してから、[`CameraVideoSource.startCapturing(with:options:)`](https://ios-sdk.api-reference.skyway.ntt.com/core/Classes/SKWCameraVideoSource.html#/c:objc(cs)SKWCameraVideoSource(im)startCapturingWithDevice:options:completion:)でキャプチャを開始します。

```swift
guard let camera = camera else {
    print("カメラの取得に失敗しました。")
}

try await CameraVideoSource.shared().startCapturing(with: camera, options: nil)
```

なお、停止したい場合は、[`CameraVideoSource.stopCapturing()`](https://ios-sdk.api-reference.skyway.ntt.com/core/Classes/SKWCameraVideoSource.html#/c:objc(cs)SKWCameraVideoSource(im)stopCapturing)をご利用ください。

### LocalVideoStreamを作成してPublishする

[`CameraVideoSource.createStream()`](https://ios-sdk.api-reference.skyway.ntt.com/core/Classes/SKWCameraVideoSource.html#/c:objc(cs)SKWCameraVideoSource(im)createStream)で `LocalVideoStream` を生成します。

生成した`LocalVideoStream` は `LocalRoomMember.publish` の引数に渡すことで `Publish` できます。

```swift
let stream = CameraVideoSource.shared().createStream()
member.publish(stream, nil)
```
