在我的应用程序中,我想在拆分视图中显示来自前后摄像头的视频:
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Canvas>
<Canvas.Background>
<VideoBrush x:Name="backBrush" />
</Canvas.Background>
</Canvas>
<Canvas Grid.Row="1">
<Canvas.Background>
<VideoBrush x:Name="frontBrush" />
</Canvas.Background>
</Canvas>
<Ellipse Fill="Red" Height="80" Width="80" Grid.RowSpan="2" />
</Grid>
在我的 C# 代码中,我为两个相机设置了源代码:
PhotoCamera frontCam;
PhotoCamera backCam;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing))
{
frontCam = new Microsoft.Devices.PhotoCamera(CameraType.FrontFacing);
frontBrush.SetSource(frontCam);
}
if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
{
backCam = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
backBrush.SetSource(backCam);
}
}
问题是,两者都fronBrush.SetSource(frontCam);
被backBrush.SetSource(backCam);
调用,但我只看到顶部后置摄像头的视频。当我更改这些命令的顺序时,我会看到来自另一台摄像机的视频。我试过 HTC 8X 和模拟器。
是某种约束,还是错误,还是我做错了什么?