Trouble with camera in Windows Phone 8.0 using videobrush

I got bug in my app and can not solve it.

Bug is - I can not use camera more than three times.

Code, that demonstrates it is here:

using System; using System.Windows; using System.Windows.Controls; using System.Windows.Navigation; using Microsoft.Phone.Controls; using Microsoft.Phone.Shell; using PhoneApp1.Resources; using System.Windows.Media; using Microsoft.Devices; namespace PhoneApp1 { public partial class MainPage : PhoneApplicationPage { PhotoCamera aCamera = new PhotoCamera(CameraType.Primary); // Constructor public MainPage() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { var cam = new camera_VM(); } } class camera_VM { public camera_VM() { VideoBrush __cameraView = new VideoBrush(); PhotoCamera aCamera = new PhotoCamera(CameraType.Primary); __cameraView.SetSource(aCamera); } } }

On third launch - it throws error:

{System.NotSupportedException: Specified method is not supported. at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.VideoBrush_SetExternalVideoPortSource(VideoBrush vb, String sPortName) at Microsoft.Devices.Camera

Have no idea - what does it mean.

My guess that having Videobrush in code - bad idea, but have I another option? I got Grid in DataTemplate, that binds to VideoBrush object.

If I must properly dispose camera unit - can anyone tell me, how to do it right?

P.S. Code is just example, that fires an error.

Category:c# Views:1 Time:2018-10-08

Related post

Copyright (C), All Rights Reserved.

processed in 0.239 (s). 11 q(s)