This repository was archived by the owner on May 1, 2024. It is now read-only.
Fixed camera preview for Xiaomi devices #1780
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Bug
CameraView
preview does not work correctly for front facing camera on Xiaomi Note 7/8 devices.This appears to be a niche issue on Xiaomi devices of a suitable age (the newer ones don't appear to show the issue) where the front camera cannot be used to preview / capture media. Instead of displaying a preview, the media capture failed event is raised & the camera cannot be used.
Below is the XCT sample running on a Xiaomi Redmi Note 7 & a Samsung A21S. The Samsung has no issues displaying the front camera and the Xiaomi cannot display it.
Xiaomi with issue
Redmi.Note_7.2022-01-02.14-50-26.mp4
Samsung without issue
SM.A217F.2022-01-02.14-52-33.mp4
Upon debugging the source code with the affected device, I found that the
ChooseOptimalSize
method was responsible for returning a resolution that could not be displayed.The following line on the affected device returns a size of
4224x3136
and when the camera is initialized the following errors are logged to the debug console:After some reading up on the
Camera2
api it looks like this lib is following the example set by Google. Stepping through the issue comes with the aspect ratio check which always seems to fail on this particular device. Maybe it is an Android flavour conflict?To sort of the issue I've added a check to see if the fallback value used is a valid size (smaller than the max preview), which will be used instead of the invalid value. This code change shouldn't affect working devices since it only alters the fallback logic and my Xiaomi is now happily giving me both cameras!
Redmi.Note_7.2022-01-02.15-08-08.mp4
Issues Fixed
Behavioral Changes
CameraView
should work on Xiaomi Redmi Note 7/8 devices 🥳I removed the else clause on this line & made the failed to retrieve camera state return early, sorry guys I love to reduce nesting in methods 😉
PR Checklist
approved