Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[camera_web] Release the camera stream of each available video input device #4621

Merged
merged 4 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 0.2.1+2

* Fixes cameraNotReadable error that prevented access to the camera on some Android devices when initializing a camera.
* Implemented support for new Dart SDKs with an async requestFullscreen API.

## 0.2.1+1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,37 @@ void main() {
);
});

testWidgets(
'releases the video stream '
'of a video input device', (tester) async {
final videoDevice = FakeMediaDeviceInfo(
'1',
'Camera 1',
MediaDeviceKind.videoInput,
);

final videoStream =
FakeMediaStream([MockMediaStreamTrack(), MockMediaStreamTrack()]);

when(mediaDevices.enumerateDevices).thenAnswer(
(_) => Future.value([videoDevice]),
);

when(
() => cameraService.getMediaStreamForOptions(
CameraOptions(
video: VideoConstraints(deviceId: videoDevice.deviceId),
),
),
).thenAnswer((_) => Future.value(videoStream));

final _ = await CameraPlatform.instance.availableCameras();

for (var videoTrack in videoStream.getVideoTracks()) {
verify(videoTrack.stop).called(1);
}
});

group('throws CameraException', () {
testWidgets(
'with notSupported error '
Expand Down
3 changes: 3 additions & 0 deletions packages/camera/camera_web/lib/src/camera_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ class CameraPlugin extends CameraPlatform {
cameras.add(camera);

camerasMetadata[camera] = cameraMetadata;

// Release the camera stream of the current video input device.
videoTracks.forEach((videoTrack) => videoTrack.stop());
} else {
// Ignore as no video tracks exist in the current video input device.
continue;
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_web
description: A Flutter plugin for getting information about and controlling the camera on Web.
repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.2.1+1
version: 0.2.1+2

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down