我正在编写一个Windows 8.1 (WINPRT)应用程序。
我使用MediaCapture API在应用程序中录制视频。
它写着:
您应该清理Windows上挂起事件中的媒体捕获资源。
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();
}
}在Windows上,清除处理程序中用于挂起应用程序生存期事件的MediaCapture资源,并在恢复事件中重新创建它们。
因此,我在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
}但是App_Resuming从不在应用程序从暂停状态恢复到前台状态后启动。
如何恢复相机资源?
发布于 2015-04-20 10:15:10
你确定你测试的正确吗?应用程序不会挂起,如果您正在调试它们(因此它们不能继续),但是您可以从Visual触发生命周期事件。
更多信息在这里:https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465115.aspx
有关使用Visual : Visual进行调试的说明防止Windows挂起附加到调试器的应用程序。这是为了允许用户在应用程序运行时查看Visual调试UI。调试应用程序时,可以使用Visual发送挂起事件。确保显示了“调试位置”工具栏,然后单击挂起图标。
https://stackoverflow.com/questions/29744356
复制相似问题