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

[camera_web] Add onCameraClosing implementation #4259

Merged
merged 8 commits into from Aug 26, 2021
Merged

[camera_web] Add onCameraClosing implementation #4259

merged 8 commits into from Aug 26, 2021

Conversation

bselwe
Copy link
Contributor

@bselwe bselwe commented Aug 24, 2021

Adds onCameraClosing implementation to the web camera platform.

  • Added onEnded to Camera (based on MediaStreamTrack.onEnded).
    • The stream of the camera video tracks that have ended playing. This occurs when there is no more camera stream data, e.g. the user has stopped the stream by changing the camera device, revoked the camera permissions or ejected the camera device.
  • Added onCameraClosing implementation.
    • Emits when the camera with the given id emits the ended event (Camera.onEnded).
  • Moved the previous camera controller's disposal to the finally clause in the example app.

Part of flutter/flutter#45297.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Note that unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

@bselwe
Copy link
Contributor Author

bselwe commented Aug 24, 2021


if (mounted) {
setState(() {});
await previousCameraController?.dispose();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't find a reason yet why CameraController.getMaxZoomLevel and CameraController.getMinZoomLevel throws a PlatformException even though this type of exception is always mapped to CameraException in these methods.

Added this to always dispose the previous camera controller even if an error occurred while initializing a new one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But maybe it should be added as a separate PR or as a part of #4240.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this should be part of #4240 instead of this one.

Copy link
Member

@ditman ditman Aug 25, 2021

Choose a reason for hiding this comment

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

(added to 4240, and reverted here)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

…ase of an uncaught exception"

This reverts commit ee5561a.
@google-cla

This comment has been minimized.

@google-cla google-cla bot added cla: no and removed cla: yes labels Aug 25, 2021
@ditman

This comment has been minimized.

@google-cla google-cla bot added cla: yes and removed cla: no labels Aug 25, 2021
Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

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

I wonder if there's a possibility that we fire the onCameraClosing event twice (if the programmer calls "stop" and the user yanks the camera from the device, or similar). Probably not, because upon calling stop we clear the tracks, right?

@ditman ditman added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Aug 26, 2021
@fluttergithubbot fluttergithubbot merged commit 56f092a into flutter:master Aug 26, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 26, 2021
fluttergithubbot pushed a commit to flutter/flutter that referenced this pull request Aug 26, 2021
@bselwe
Copy link
Contributor Author

bselwe commented Aug 26, 2021

I wonder if there's a possibility that we fire the onCameraClosing event twice (if the programmer calls "stop" and the user yanks the camera from the device, or similar). Probably not, because upon calling stop we clear the tracks, right?

Yeah, I believe so. Stopping the camera programatically stops all stream tracks (both video and audio) so they should no longer emit events about the stream being stopped for another reason.

I have tested this, stopped the camera programmatically, then rejected the camera permissions. Normally, it emits an ended event but it didn't as the camera was stopped so it is fine I think.

fotiDim pushed a commit to fotiDim/plugins that referenced this pull request Sep 13, 2021
amantoux pushed a commit to amantoux/plugins that referenced this pull request Sep 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes p: camera platform-web waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
3 participants