> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-v6-beta2-flutter-uikit.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Video Controls

Control video during an active call session. These methods allow you to pause/resume the local camera and switch between front and rear cameras.

## Prerequisites

* An active [call session](/calls/flutter/join-session)
* Access to the `CallSession` instance
* Camera permissions granted

## Get CallSession Instance

All video control methods are called on the `CallSession` singleton:

```dart theme={null}
CallSession? callSession = CallSession.getInstance();
```

<Note>
  `CallSession.getInstance()` returns `null` if no active session exists. Always use the null-aware `?.` operator when calling methods.
</Note>

***

## Pause Video

Turn off the local camera. Other participants will see a placeholder instead of your video feed.

```dart theme={null}
await CallSession.getInstance()?.pauseVideo();
```

<Note>
  When you pause your video, the `onVideoPaused()` callback is triggered on your `MediaEventsListener`.
</Note>

***

## Resume Video

Turn on the local camera to resume transmitting video.

```dart theme={null}
await CallSession.getInstance()?.resumeVideo();
```

<Note>
  When you resume your video, the `onVideoResumed()` callback is triggered on your `MediaEventsListener`.
</Note>

***

## Toggle Pause Video

Convenience method that toggles between paused and resumed video. It checks the current state and calls the appropriate action automatically.

```dart theme={null}
await CallSession.getInstance()?.togglePauseVideo();
```

***

## Switch Camera

Toggle between the front-facing and rear cameras.

```dart theme={null}
await CallSession.getInstance()?.switchCamera();
```

<Note>
  When the camera is switched, the `onCameraFacingChanged(CameraFacing)` callback is triggered on your `MediaEventsListener`.
</Note>

### CameraFacing Enum

| Value                | Description                         |
| -------------------- | ----------------------------------- |
| `CameraFacing.front` | Front-facing camera (selfie camera) |
| `CameraFacing.rear`  | Rear camera                         |

***

## Toggle Camera Source

Convenience method that toggles between front and rear camera. Equivalent to `switchCamera()`.

```dart theme={null}
await CallSession.getInstance()?.toggleCameraSource();
```

***

## Check Video Pause State

Use the `isVideoPaused` state getter to check whether the local camera is currently paused.

```dart theme={null}
bool? videoPaused = CallSession.getInstance()?.isVideoPaused;
```

| Return Type | Description                                                               |
| ----------- | ------------------------------------------------------------------------- |
| `bool?`     | `true` if video is paused, `false` otherwise, `null` if no active session |

***

## Listen for Video Events

Register a `MediaEventsListener` to receive callbacks when video state changes:

```dart theme={null}
CallSession.getInstance()?.addMediaEventsListener(MediaEventsListener(
  onVideoPaused: () {
    debugPrint("Video paused");
    // Update UI to show video off state
  },
  onVideoResumed: () {
    debugPrint("Video resumed");
    // Update UI to show video on state
  },
  onCameraFacingChanged: (CameraFacing cameraFacing) {
    debugPrint("Camera switched to: $cameraFacing");
    // Update UI to reflect camera change
  },
));
```

<Note>
  Flutter listeners are not lifecycle-aware. You must manually remove listeners in your widget's `dispose()` method to prevent memory leaks.
</Note>

***

## Initial Video Settings

You can configure the initial video state when joining a session using `SessionSettings`:

```dart theme={null}
SessionSettings sessionSettings = CometChatCalls.SessionSettingsBuilder()
    .startVideoPaused(true)                            // Start with camera off
    .setInitialCameraFacing(CameraFacing.front)        // Start with front camera
    .setType(SessionType.video)                        // Video call (not audio-only)
    .build();
```

***

## Hide Video Controls in UI

You can hide the built-in video control buttons using `SessionSettings`:

```dart theme={null}
SessionSettings sessionSettings = CometChatCalls.SessionSettingsBuilder()
    .hideToggleVideoButton(true)   // Hide the video on/off button
    .hideSwitchCameraButton(true)  // Hide the camera flip button
    .build();
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Recording" icon="circle-dot" href="/calls/flutter/recording">
    Record call sessions
  </Card>

  <Card title="Media Events Listener" icon="bell" href="/calls/flutter/media-events-listener">
    Handle all media events
  </Card>
</CardGroup>
