【发布时间】:2015-04-20 09:43:57
【问题描述】:
我正在编写一个 Windows Phone 8.1 (WINPRT-XAML) 应用程序。
我正在使用 MediaCapture API 在应用中录制视频。
上面写着:
您应该在 Windows Phone 上的 Suspending 事件中清理媒体捕获资源。
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 Phone 上,清理处理程序中的 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 在应用从挂起状态恢复到前台状态后永远不会启动。
如何恢复相机资源?
【问题讨论】:
标签: c# windows-phone windows-phone-8.1