I am writing a Windows Phone 8.1 (WINPRT-XAML) App.
I am using MediaCapture API to record videos in app.
It is written:
You should cleanup media capture resources in the Suspending event on Windows Phone.
private async void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//cleanup camera resources
await CleanupCaptureResources();
deferral.Complete();
}
public async Task CleanupCaptureResources()
{
if (IsRecording && MediaCapture != null)
{
await MediaCapture.StopRecordAsync();
IsRecording = false;
}
if (IsPreviewing && MediaCapture != null)
{
await MediaCapture.StopPreviewAsync();
IsPreviewing = false;
}
if (MediaCapture != null)
{
if (PreviewElement != null)
{
PreviewElement.Source = null;
}
MediaCapture.Dispose();
}
}
On Windows Phone, clean up your MediaCapture resources in the handler for the Suspending app lifetime event and recreate them in the Resuming event.
So I added below lines in App.cs:
public App()
{
this.InitializeComponent();
this.Suspending += this.OnSuspending;
this.Resuming += this.App_Resuming;
}
void App_Resuming(object sender, object e)
{
//TODO: RESUME CAMERA PREVIEW and MediaCapture object here
}
But App_Resuming
never launches after app is resuming from Suspended to Foreground State.
How can I resume the Camera resources?
Are you sure that you're testing this correctly? Applications won't suspend if you're debugging them (so they can't resume), but you can trigger the lifecycle events from Visual Studio.
More info here: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465115.aspx
A note about debugging using Visual Studio: Visual Studio prevents Windows from suspending an app that is attached to the debugger. This is to allow the user to view the Visual Studio debug UI while the app is running. When you're debugging an app, you can send it a suspend event using Visual Studio. Make sure the Debug Location toolbar is being shown, then click the Suspend icon.