简体   繁体   中英

Showing video from front and back camera at the same time in Windows Phone

In my app I want to show video from the front and back cameras in a split view:

<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>

In my C# code I set source for both cameras:

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);
        }
    }

The problem is, that both fronBrush.SetSource(frontCam); and backBrush.SetSource(backCam); get called but I only see video from the back camera in the top. When I change the order of these commands, I see video from the other camera. I tried HTC 8X and emulators.

Is it some kind of a constrain, or a bug, or am I doing something wrong?

Yeah - I'm having the same problem. Wanted to do the exact same thing. Based upon my knowledge its not possible to have two camera instances running at the same time. Let me know if you hear anything different!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM