Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if AVCaptureSession preset resolution is supported in Swift

For instance, I may want to set it to hd1280x720, but only if it's supported, and use a lower res that is supported otherwise.

session = AVCaptureSession()
if(**my device supports hd1280x720**){
  session!.sessionPreset = AVCaptureSession.Preset.hd1280x720
}else if(**my device supports 640x480**){
  session!.sessionPreset = AVCaptureSession.Preset.vga640x480
}
like image 232
Chewie The Chorkie Avatar asked Jan 29 '26 21:01

Chewie The Chorkie


1 Answers

Use AVCaptureSession.canSetSessionPreset(_:):

Returns a Boolean value that indicates whether the receiver can use the given preset.

like image 79
Martin R Avatar answered Feb 01 '26 14:02

Martin R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!