首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >应用程序暂停后恢复相机资源

应用程序暂停后恢复相机资源
EN

Stack Overflow用户
提问于 2015-04-20 09:43:57
回答 1查看 836关注 0票数 1

我正在编写一个Windows 8.1 (WINPRT)应用程序。

我使用MediaCapture API在应用程序中录制视频。

API文档

它写着:

您应该清理Windows上挂起事件中的媒体捕获资源。

代码语言:javascript
复制
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中添加了以下行:

代码语言:javascript
复制
 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从不在应用程序从暂停状态恢复到前台状态后启动。

如何恢复相机资源?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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发送挂起事件。确保显示了“调试位置”工具栏,然后单击挂起图标。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29744356

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档