setResolution method
Sets the capture resolution in pixels.
The value is a target: each platform negotiates the closest supported size with the device (a portrait request maps to the equivalent landscape sensor size on mobile). The actual size is available through getWidth/getHeight and every captureFrame result. Returns false when no camera is open.
Implementation
@override
Future<bool> setResolution(int width, int height) async {
final tracks = _stream?.getVideoTracks().toDart;
if (tracks == null || tracks.isEmpty) return false;
try {
// Browsers treat these as ideals and pick the closest supported mode,
// the same negotiation the native platforms do.
await tracks.first
.applyConstraints(dom.MediaTrackConstraints(
width: width.toJS, height: height.toJS))
.toDart;
return true;
} catch (e) {
return false;
}
}