Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/camera/camera_windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 0.2.6+3

* Removes usage of the deprecated and ignored `maxVideoDuration` in the example.
* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7.

## 0.2.6+2
Expand Down
73 changes: 12 additions & 61 deletions packages/camera/camera_windows/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class _MyAppState extends State<MyApp> {
int _cameraId = -1;
bool _initialized = false;
bool _recording = false;
bool _recordingTimed = false;
bool _previewPaused = false;
Size? _previewSize;
MediaSettings _mediaSettings = const MediaSettings(
Expand Down Expand Up @@ -146,7 +145,6 @@ class _MyAppState extends State<MyApp> {
_cameraIndex = 0;
_previewSize = null;
_recording = false;
_recordingTimed = false;
_cameraInfo =
'Failed to initialize camera: ${e.code}: ${e.description}';
});
Expand All @@ -165,7 +163,6 @@ class _MyAppState extends State<MyApp> {
_cameraId = -1;
_previewSize = null;
_recording = false;
_recordingTimed = false;
_previewPaused = false;
_cameraInfo = 'Camera disposed';
});
Expand All @@ -190,56 +187,22 @@ class _MyAppState extends State<MyApp> {
_showInSnackBar('Picture captured to: ${file.path}');
}

Future<void> _recordTimed(int seconds) async {
if (_initialized && _cameraId > 0 && !_recordingTimed) {
unawaited(
CameraPlatform.instance.onVideoRecordedEvent(_cameraId).first.then((
VideoRecordedEvent event,
) async {
if (mounted) {
setState(() {
_recordingTimed = false;
});

_showInSnackBar('Video captured to: ${event.file.path}');
}
}),
);

await CameraPlatform.instance.startVideoRecording(
_cameraId,
maxVideoDuration: Duration(seconds: seconds),
);

if (mounted) {
setState(() {
_recordingTimed = true;
});
}
}
}

Future<void> _toggleRecord() async {
if (_initialized && _cameraId > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The check _cameraId > 0 seems incorrect. Camera IDs are non-negative integers, so camera ID 0 is valid. This check prevents video recording on the first available camera. It should probably be _cameraId >= 0.

Suggested change
if (_initialized && _cameraId > 0) {
if (_initialized && _cameraId >= 0) {

if (_recordingTimed) {
/// Request to stop timed recording short.
await CameraPlatform.instance.stopVideoRecording(_cameraId);
if (!_recording) {
await CameraPlatform.instance.startVideoRecording(_cameraId);
} else {
if (!_recording) {
await CameraPlatform.instance.startVideoRecording(_cameraId);
} else {
final XFile file = await CameraPlatform.instance.stopVideoRecording(
_cameraId,
);
final XFile file = await CameraPlatform.instance.stopVideoRecording(
_cameraId,
);

_showInSnackBar('Video captured to: ${file.path}');
}
_showInSnackBar('Video captured to: ${file.path}');
}

if (mounted) {
setState(() {
_recording = !_recording;
});
}
if (mounted) {
setState(() {
_recording = !_recording;
});
}
}
}
Expand Down Expand Up @@ -407,19 +370,7 @@ class _MyAppState extends State<MyApp> {
const SizedBox(width: 5),
ElevatedButton(
onPressed: _initialized ? _toggleRecord : null,
child: Text(
(_recording || _recordingTimed)
? 'Stop recording'
: 'Record Video',
),
),
const SizedBox(width: 5),
ElevatedButton(
onPressed:
(_initialized && !_recording && !_recordingTimed)
? () => _recordTimed(5)
: null,
child: const Text('Record 5 seconds'),
child: Text(_recording ? 'Stop recording' : 'Record Video'),
),
if (_cameras.length > 1) ...<Widget>[
const SizedBox(width: 5),
Expand Down
9 changes: 3 additions & 6 deletions packages/camera/camera_windows/lib/camera_windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,11 @@ class CameraWindows extends CameraPlatform {
@override
Future<List<CameraDescription>> availableCameras() async {
try {
final List<String?> cameras = await _hostApi.getAvailableCameras();
final List<String> cameras = await _hostApi.getAvailableCameras();

return cameras.map((String? cameraName) {
return cameras.map((String cameraName) {
return CameraDescription(
// This type is only nullable due to Pigeon limitations, see
// https://github.com/flutter/flutter/issues/97848. The native code
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fixed a while ago, I just missed updating this when I updated the Pigeon file.

// will never return null.
name: cameraName!,
name: cameraName,
// TODO(stuartmorgan): Implement these; see
// https://github.com/flutter/flutter/issues/97540.
lensDirection: CameraLensDirection.front,
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_windows/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_windows
description: A Flutter plugin for getting information about and controlling the camera on Windows.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_windows
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.2.6+2
version: 0.2.6+3

environment:
sdk: ^3.7.0
Expand Down