Hi,,
I am working on windows phone 7 Flash light application. I have used the torch light sample application class to implement the required functionality in my application. For that I am using Videocamera class. Please see the following piece of code
Assembly mediaExtendedAssembly = Assembly.Load("Microsoft.Phone.Media.Extended, Version=7.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e");
.......
.....
Type videoCameraType = mediaExtendedAssembly.GetType("Microsoft.Phone.VideoCamera");
ConstructorInfo videoCameraConstructor = videoCameraType.GetConstructor(new Type[] { cameraSourceType });
_videoCamera = videoCameraConstructor.Invoke(new object[] { cameraSource });
// Set the properties and methods.
_videoCameraLampEnabledPropertyInfo = videoCameraType.GetProperty("LampEnabled");
_videoCameraStartRecordingMethod = videoCameraType.GetMethod("StartRecording");
.....
.....
public void StartRecording()
{
// Invoke the start recording method on the video camera object.
_videoCameraStartRecordingMethod.Invoke(_videoCamera, new object[0]);
}
Using the above code it was able to set the flash light on. Inorder to stop the flash light, I have added following lines to the above code.
_videoCameraStopRecordingMethod = videoCameraType.GetMethod("StopRecording");
public void StopRecording()
{
_videoCameraStopRecordingMethod.Invoke(_videoCamera, null);
}
ie: By passing null as a parameter it was able to stop the flash light. Like this way I am turning ON and OFF the FlashLight for 2 to 3 times. But If I navigate from the current page to next page and comes back to the flash application page ,it is crashing at the time of Initialisation.
ie: while calling the line,
_cameraVisualizerSetSourceMethod.Invoke(_cameraVisualizer, new object[] { camera.InnerCameraObject });
I couldn't dispose the video camera objects. Couldn't free its resources. Even if I set null to videocamera object ,its not getting deinitialised. Could you please tell me how to free its resources.
Any kind of help would be greatly appreciated.
Thanks,
Aswathy.
Loading
Abhishek JainPosted Aug 30, 2013, 8:24 AM
Private PhotoCamera _videoCamera;
Regards
AJ
Aswathy ADPosted Aug 30, 2013, 6:25 AM
Thanks for ur quick reply. Can't use Dispose() function as there is no built in function for _videocamera object.
I am declaring the videocamera object as follows.
Private object _videoCamera;
and _videoCamera doesn't have any built in functions for disposing.
So I tried the following code:
_videoCamera = null;
GC.Collect();
These lines make the app more stable. Now the probability of crashing has been reduced.
Still it would be more helpful if u could suggest a better method than this. Once again thanks for showing interest in this query.
thanks,
Aswathy.
Abhishek JainPosted Aug 30, 2013, 6:13 AM
Aswathy ADPosted Aug 30, 2013, 4:11 AM
I should dispose the objects in OnNavigatedFrom() function . But even if I set the videocamera object to null,, it is crashing. Could u please tell me the proper way of disposing the objects.
Waiting for ur reply.
thanks,
Aswathy.
Abhishek JainPosted Aug 30, 2013, 3:21 AM
May be you can try this link it will provide you some help:
http://msdn.microsoft.com/en-us/magazine/hh708750.aspx
Regards
AJ