Laerdal / Xamarin.AzureCommunicationCalling

Xamarin iOS and Android binding libraries for Microsofts Azure Communication Services
MIT License
35 stars 11 forks source link

LocalVideoStream.switchSource is missing in Android #25

Closed kungbernard closed 2 years ago

kungbernard commented 2 years ago

Hi and thank you for creating this package. It has been a great move to utilize Azure Communication Services in Xamarin.

When I am testing on the Test app project, I have been successfully add the switch camera for iOS but when moving into Android, the switchSource in LocalVideoStream is missing

I have a look into the Microsoft docs and there should be a switchSource method https://docs.microsoft.com/en-us/java/api/com.azure.android.communication.calling.localvideostream.switchsource?view=communication-services-java-android

Would it be possible to add that back to the library?

Below is how I do switch camera in iOS:

public void SwitchCamera()
        {
            var currentCamera = _localVideoStream.Source;

            var flipToCamera = currentCamera.CameraFacing == ACSCameraFacing.Front ? ACSCameraFacing.Back : ACSCameraFacing.Front;

            var cam = _deviceManager.Cameras.Where(c => c.CameraFacing == flipToCamera).FirstOrDefault();

            if(cam != null )
            {
                void onSwtichCameraCompleted(NSError onSwtichCameraError)
                {
                    if (onSwtichCameraError != null)
                    {
                        Debug.WriteLine(onSwtichCameraError);
                    }

                    return;
                }

                _localVideoStream.SwitchSource(cam, onSwtichCameraCompleted);
            }
        }

Thanks alot!

tompi commented 2 years ago

Hey! Nice to hear you could use the nugets.

The binding tools barfs on the "CompletableFuture" types, so I needed to create a separate wrapper that returns the underlying type instead of the completablefuture...

You need to use the "CallClientHelper" for this, you can do it like this:

CallClientHelper.SwitchCameraSource(_localVideoStream,
                _deviceManager.Cameras.First(c => c.CameraFacing == CameraFacing.Back));

CallClientHelper is in this package: https://www.nuget.org/packages/Xamarin.AzureCommunicationCallingHelper.Android/2.0.0-beta.1.1

kungbernard commented 2 years ago

Thanks alot @tompi

Just found that there's a beta version available for the helper

Found the helper method now, Thanks again!