Judson Abraham
Judson Abraham

Reputation: 412

Video preview not showing in Xamarin forms

I'm doing video call implementation using Linphone. I am able to capture the camera in my phone and showing the preview of video in my app. But I need the preview of the video being captured in client camera. I'm capturing the video through texture view. This is my texture view code where I'm displaying my camera

 async Task PrepareSession()
    {
        IsBusy = true;
     
        try
        {
            CloseSession();
            sessionBuilder = device.CreateCaptureRequest(cameraTemplate);

            List<Surface> surfaces = new List<Surface>();
            if (texture.IsAvailable && previewSize != null)
            {
                LinearLayout fl = new LinearLayout(this.Context);
                ViewGroup.LayoutParams lparams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                fl.LayoutParameters = lparams;

                displayCamera = new TextureView(this.Context);
                ViewGroup.LayoutParams dparams = new ViewGroup.LayoutParams(100, 100);
                displayCamera.LayoutParameters = dparams;

                captureCamera = new TextureView(this.Context);
                ViewGroup.LayoutParams cparams = new ViewGroup.LayoutParams(100, 100);
                captureCamera.LayoutParameters = cparams;

                fl.AddView(displayCamera);
                fl.AddView(captureCamera);
             
                var texture = this.texture.SurfaceTexture;
                texture.SetDefaultBufferSize(previewSize.Width, previewSize.Height);
                               
                Core.VideoDisplayEnabled = true;
                Core.VideoCaptureEnabled = true;
                Core.NativeVideoWindowId = displayCamera.Handle;
                Core.NativePreviewWindowId = captureCamera.Handle;

              
                Surface previewSurface = new Surface(texture);
                surfaces.Add(previewSurface);
                sessionBuilder.AddTarget(previewSurface);
                
            }

This is the Linphone code through which they display the video preview of client camera.

TextureView captureCamera;
LinearLayout fl = new LinearLayout(this);
            ViewGroup.LayoutParams lparams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
            fl.LayoutParameters = lparams;         
            captureCamera = new TextureView(this);
            ViewGroup.LayoutParams cparams = new ViewGroup.LayoutParams(320, 240);
            captureCamera.LayoutParameters = cparams;
            fl.AddView(captureCamera);
            app.getLayoutView().Children.Add(fl);
            app.Core.NativePreviewWindowId = captureCamera.Handle;
            app.Core.VideoCaptureEnabled = true;

I have tried the following code combination

Core.NativeVideoWindowId = texture.Handle;

I am getting object not found exception for Core.NativeVideoWindowId. How can I add video preview directly in the layout and simply get it by it's ID. I have gone through the following link.

https://github.com/BelledonneCommunications/linphone-xamarin

How to show a textureview through stacklayout in xamarin forms?

https://gitlab.linphone.org/BC/public/tutorials

I have no clue how to fix this. Any suggestions?

Upvotes: 0

Views: 185

Answers (1)

Viish
Viish

Reputation: 503

If you want to display the remote video view you must use Core.NativeVideoWindowId instead of Core.NativePreviewWindowId. You really should take a look at our tutorials, that would help you understand how our API works better: https://gitlab.linphone.org/BC/public/tutorials

Best regards,

Upvotes: 1

Related Questions