Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
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
4 changes: 4 additions & 0 deletions packages/camera/camera_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## NEXT

* Fix cameraNotReadable error that prevented access to the camera on some Android devices.

## 0.2.0

* Initial release, adapted from the Flutter [I/O Photobooth](https://photobooth.flutter.dev/) project.
2 changes: 1 addition & 1 deletion packages/camera/camera_web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The web implementation of [`camera`][camera].
### Depend on the package

This package is not an [endorsed implementation](https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin)
of the google_maps_flutter plugin yet, so you'll need to [add it explicitly](https://pub.dev/packages/camera_web/install).
of the camera plugin yet, so you'll need to [add it explicitly](https://pub.dev/packages/camera_web/install).

## Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,33 @@ void main() {
).called(1);
});

testWidgets(
'releases the camera stream '
'used to request video and audio permissions', (tester) async {
final videoTrack = MockMediaStreamTrack();

var videoTrackStopped = false;
when(videoTrack.stop).thenAnswer((_) {
videoTrackStopped = true;
});

when(
() => cameraService.getMediaStreamForOptions(
CameraOptions(
audio: AudioConstraints(enabled: true),
),
),
).thenAnswer(
(_) => Future.value(
FakeMediaStream([videoTrack]),
),
);

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

expect(videoTrackStopped, isTrue);
});

testWidgets(
'gets a video stream '
'for a video input device', (tester) async {
Expand Down
5 changes: 4 additions & 1 deletion packages/camera/camera_web/lib/src/camera_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,15 @@ class CameraPlugin extends CameraPlatform {
}

// Request video and audio permissions.
await _cameraService.getMediaStreamForOptions(
final cameraStream = await _cameraService.getMediaStreamForOptions(
CameraOptions(
audio: AudioConstraints(enabled: true),
),
);

// Release the camera stream used to request video and audio permissions.
cameraStream.getVideoTracks().forEach((videoTrack) => videoTrack.stop());

// Request available media devices.
final devices = await mediaDevices.enumerateDevices();

Expand Down