Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External camera support (along with front and back cameras) #20

Open
abbas2501 opened this issue Oct 21, 2022 · 8 comments
Open

External camera support (along with front and back cameras) #20

abbas2501 opened this issue Oct 21, 2022 · 8 comments
Labels
enhancement New feature or request

Comments

@abbas2501
Copy link

Thanks for the amazing package! I have a use case where I need to use a third camera (a webcam) connected to my phone (alongside the front and back cameras).

Describe the solution you'd like
Ability to switch between three cameras (or more in a loop) using the switch camera button.

@abbas2501 abbas2501 added the enhancement New feature or request label Oct 21, 2022
@ThibaultBee
Copy link
Member

Hi,

Glad you like the project :)

This is a huge work and we are not sure that that the native iOS and Android library we used does support external camera and we are not even sure that iOS and Android phone support to connect a third camera.
We are not going to implement this in short term or medium term. We do not have the resources for this but if you submit a PR we will definitely have a look on it 👍

I am curious though. How is the third camera connected? USB or Wi-Fi? What type of camera it is?

@abbas2501
Copy link
Author

abbas2501 commented Oct 21, 2022

HI @ThibaultBee

Thanks for reverting!

For the last part of your comment - Its just another web camera connected via OTG to the android phone. I'm able to use the camera on dedicated apps for this use case. One for example - USB Camera App

I'm unsure of iOS but android does support more cameras than the native device cameras.

For example - take a look at this flutter package for RTMP streaming (i used is previously in our app but it doesn't seem to be well maintained and has bugs, this is when I moved to yours, and it's been a fruitful switch). The package has a method that returns a list of all cameras (front, back, external). Probably it can be a starting point in building out this support. Will look into it.
video_stream

I'll look into creating a PR if I find success in trying it out.

Thanks!

@abbas2501
Copy link
Author

Hi @ThibaultBee

Here's an update from my research so far -

Along with LENS_FACING_BACK & LENS_FACING_FRONT we also have -
LENS_FACING_EXTERNAL

This gives us access to external cameras. For this, changes are required on your StreamPack package, which only exposes getFrontCameras and getBackCameras on LENS_FACING_FRONT & LENS_FACING_BACK respectively. If it can expose a new method getExternalCameras() based on LENS_FACING_EXTERNAL, that will do the work.

I have created a fork for myself of the StreamPack package but I'm stuck at importing the fork into the flutter package (instead of the original StreamPack package).

Will you entertain a PR on StreamPack? I've added one single method getExternalCameras().

Thanks!

@ThibaultBee
Copy link
Member

Nice ;)

Yes, I can accept PR on StreamPack as well.

@tibfox
Copy link

tibfox commented Nov 6, 2022

woudl be great to also have influence on the initial orientation of the selected camera. if I switch from landscape-back to front the orientation is portrait in default. If I switch back to the back camera it is still portrait even thought it has been landscape before.

@ThibaultBee
Copy link
Member

@tibfox sorry I miss your message. As your issue is not related, please open a new issue.

@abbas2501 If you use CameraPosition.other it will use the external camera if one is connected and detected by camera2.
There are still no way to return the camera list.

@shabirsaddique1
Copy link

Any updates related to the external camera connection tried CameraPosition.other but still, it returned an exception failed to set the camera position, and the empty list in returned but the camera is connected with the phone through OTG. I was able to connect the external camera to Android native but was not able to send an external video source so it could start streaming through that external source.

@ThibaultBee
Copy link
Member

External cameras are supported via camera2 API but this have never been tested because I don't have a phone that
supports external cameras.

I am not sure an Android device support external cameras via camera2.

There is feature flag to check if your device supports this feature:
see https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_CAMERA_EXTERNAL

Could you test something like that:


/**
 * Get if the system supports the given feature.
 *
 * @param featureName the feature name from [PackageManager.FEATURE_*]
 * @return true if the feature is supported, false otherwise
 */
fun Context.hasSystemFeature(featureName: String) = packageManager.hasSystemFeature(featureName)

/**
 * Get if the system supports external cameras.
 *
 * @return true if the feature is supported, false otherwise
 */
fun Context.hasExternalCamera() = hasSystemFeature(PackageManager.FEATURE_CAMERA_EXTERNAL)

Then, run:

Log.e("TEST", "External camera support: ${context.hasExternalCamera()}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants