getIsFrontCamera method

Future<bool> getIsFrontCamera()

Implementation

Future<bool> getIsFrontCamera() async {
  // Enumerate all available media devices
  List<MediaDeviceInfo> devices =
      await navigator.mediaDevices.enumerateDevices();

  // Filter the devices to find video input devices
  List<MediaDeviceInfo> videoDevices =
      devices.where((device) => device.kind == 'videoinput').toList();

  // Match the track with the devices
  for (var device in videoDevices) {
    if (device.deviceId == videoTrack?.getSettings()["deviceId"]) {
      // Check if the device label contains "front" or "back"
      if (device.label.toLowerCase().contains('front')) {
        return true;
      } else if (device.label.toLowerCase().contains('back')) {
        return false;
      }
    }
  }

  // If the label does not explicitly mention "front" or "back", you may need additional logic
  // or assume a default (e.g., false for back camera)
  return false; // Default assumption
}