我用你的答案解决了同样的问题,但我认为在这个例子中缺少一些代码(对于下一个人,有同样的问题),所以我发布了对我有用的代码。
对于 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>
对于安卓
我在 Linphone Xamarin 示例项目中使用了 BelledonneCommunications 的代码,它对我有用
示例项目可以在这里找到:
https://github.com/BelledonneCommunications/linphone-xamarin
检查文件:MainActivity.cs(android项目)