0x80131515 is thrown when the camera starts

I get the above error when trying to install PhotoCamera as the source for VideoBrush with code:

camera = new PhotoCamera();
var videoBrush = new VideoBrush();
videoBrush.SetSource(camera);
AR.Background = videoBrush;

I get the following stack trace:

0x80131515
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.VideoBrush_SetExternalVideoSource(VideoBrush vb, IntPtr& videoSessionHandle)
at System.Windows.Media.VideoBrush.SetUpExternalVideoSession()
at Microsoft.Devices.CameraVideoBrushExtensions.SetSource(VideoBrush brush, Camera camera)
at MyClass.MyFunction()
at System.Windows.Controls.Frame.FireEventHandler[T](EventHandler`1 handler, Object sender, OrientationChangedEventArgs args)
at Microsoft.Phone.Controls.PhoneApplicationPage.UIOrientationChange(ShellPageOrientation orientation)

It is excluded if I have an attached debugger.

Thank.

+3
source share
2 answers

Ok, now I solved it. I think the solution can be appreciated by others, so here it is:

It seems you cannot assign PhotoCamera as the source for the software-created VideoBrush, so I edited my xaml to contain

<Rectangle>
    <Rectangle.Fill>
        <VideoBrush x:Name="VB" />
    </Rectangle.Fill>
</Rectangle>

This was followed by simpler code.

VB.SetSource(new PhotoCamera());

In addition, this code is contained in the OnOrientationChanged event, which appears several times, therefore is contained in

if (!processing)
{
    processing = true;

    VB.SetSource(new PhotoCamera());

    var bw = new BackgroundWorker();
    bw.DoWork += (object, sender) => {
        Thread.Sleep(250);
        processing = false;
    }
}

the code runs smoothly.

+2
source

FrontFacing new PhotoCamera(CameraType.FrontFacing) SetSource() . CameraType.Primary VideoBrush. ?

0

All Articles