Linphone 和 Xamarin 表单;如何设置远程和本地视图?

Linphone and Xamarin Forms; how to set remote and local views?

基于 Linphone Windows 10 app implementation,我可以通过设置属性来查看远程和本地视频 Linphone.Core.NativeVideoWindowIdNativePreviewVideoWindowId 到两个 Windows.UI.Xaml.Controls.SwapChainPanel 控件的相应 Name:s。

在相应的Xamarin AndroidiOS[=中使用Linphone时25=] 应用程序,然后应该使用哪个 UI 控件,以及应该使用哪个控件 属性 来定义这些平台上的 NativeVideoWindowIdNativePreviewVideoWindowId

我也遇到过类似的问题

Android:

videoView = new GL2JNIView(context);
surfaceView = new SurfaceView(context);

通过自定义渲染器分配,例如 ViewRenderer<CameraPreview, Droid.Lib.CameraPreview>

iOS:

 var wrapper = (Xamarin.Forms.Platform.iOS.NativeViewWrapper)contentViewVideoParent.Content;
                var videoview = (UIView)wrapper.NativeView;

并将 IntPtr videoview.Handle 分配给 linphone 视图。

我已经用你的答案解决了同样的问题,但我认为在这个例子中缺少一些代码(对于下一个人,有同样的问题),所以我 post 对我有用的代码。

对于 iOS:


AppDelegate.cs(iOS 项目)

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init();
    LoadApplication(new App(IntPtr.Zero));
    View view = null;
    UIView iView = new UIView(new RectangleF(0,0,640,480));
    view = iView.ToView();
    ((App)App.Current).ViedoFrame().Content = view;
    NativeViewWrapper wrapper = (NativeViewWrapper)((App)App.Current).ViedoFrame().Content;
    UIView uiView = (UIView)wrapper.NativeView;
    ((App)App.Current).Core.NativePreviewWindowId = uiView.Handle;
    ((App)App.Current).Core.VideoDisplayEnabled = true;
    ((App)App.Current).Core.VideoPreviewEnabled = true;
    
    return base.FinishedLaunching(app, options);
}

App.cs(共享项目)

public partial class App : Application
{
    ...
    
    public Page MainPageContent;
    
    public App(IntPtr context)
    {
        InitializeComponent();
        MainPageContent = new MainPage();
        MainPage = new NavigationPage(MainPageContent);
    }
    
    public ContentView ViedoFrame()
    {
        return MainPageContent.FindByName<ContentView>("video_frame");
    }
    
    ...
}

MainPage.xaml(共享项目)

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:Kiwi"
             x:Class="Project.Linphone"
             Title="KiwiDoorUni">
             
    <ContentPage.ToolbarItems>
        ...
    </ContentPage.ToolbarItems>
    
    <StackLayout>
        ...
        <ContentView x:Name="video_frame">
        <!-- leave blank, UIView will be inserted here -->
        </ContentView>
    </StackLayout>
</ContentPage>

为 android


我在 Linphone Xamarin 示例项目中使用了 BelledonneCommunications 的代码,它对我有用

示例项目可以在这里找到:

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

检查文件:MainActivity.cs(android 项目)