问题描述
对于 Windows Phone 8.1 应用,我必须录制视频.
For a Windows Phone 8.1 app I have to record a video.
我使用了这个说明,它基本上有效......http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868171.aspx
I used this instructions and it works basically...http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868171.aspx
...但我没有得到 App.xaml.cs 中的清理部分
... but I do not get the cleaning up part within the App.xaml.cs
public MediaCapture MediaCapture { get; set; }
public CaptureElement PreviewElement { get; set; }
public bool IsRecording { get; set; }
public bool IsPreviewing { get; set; }
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();
}
}
private async void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//cleanup camera resources
await CleanupCaptureResources();
deferral.Complete();
}
我不明白 App.xaml.cs 和 VideoRec.xaml(预览元素所在的地方)之间的连接是如何工作的.这可能是一件非常基本的事情......我非常感谢初学者如何处理 MediaCapture 的每个提示或教程链接.我发现的一切都是为了高级.
I don't get how the connection between App.xaml.cs and VideoRec.xaml (whrere the preview element is) has to work.This is probably a very basic thing... I am very grateful for every hint or a link for a tutorial for beginners how to handle MediaCapture at all. Everything I have found is for advanced.
推荐答案
我想说的是,适当的清洁 MediaCapture 是拍摄照片/视频最重要的部分,也是 MSDN 说:
I would say that proper cleaning MediaCapture is the most important part of takieng a photo/video also MSDN says:
注意在 Windows Phone 上,音乐和媒体应用程序应清理 Suspending 事件处理程序中的 MediaCapture 对象和相关资源,并在 Resuming 事件处理程序中重新创建它们.
如果不清理 MediaCapture 元素会发生什么?- 就我而言,当我尝试使用 MediaCapture(例如默认照片应用程序)运行其他应用程序时,我的手机挂了.
What happens when you don't clean your MediaCapture element? - in my case, when I've tried, my phone hung when I've run other application using MediaCapture (for example default photo app).
回到你的问题 - App.xaml.cs 和 VideoREc.xaml 之间的连接 - 看看所有变量(在这种情况下是属性)MediaCapture
、PreviewElement
、IsRecording
和 IsPreviewing
在 App
类中定义 - 它们是为整个应用程序定义的.我怀疑 VideoRec.xaml 仅使用了 App.xaml.cs 中定义的那些属性的引用.
Going back to your question - connection between App.xaml.cs and VideoREc.xaml - look that all variables (properties in this case) MediaCapture
, PreviewElement
, IsRecording
and IsPreviewing
are defined in class App
- they are defined for the whole app. I suspect that VideoRec.xaml uses only a reference of those properties defined in App.xaml.cs.
您还应该知道 Suspending/Resuming 事件是为整个应用程序定义的,并且在发生此类事件时都会触发它们.它什么时候发生?- 在你离开你的应用程序之后(只注意调试模式 - 连接到计算机时它的工作方式几乎没有什么不同).详细了解 MSDN 上的生命周期事件.这些事件是清理/恢复 MediaCapture 资源的最佳事件.
You should also be aware that Suspending/Resuming events are defined for the whole app and they are all fired when such an event occurs. When does it occur? - just after you navigate away from your app (only look out for Debug mode - it works little different when connected to computer). More about lifecycle events at MSDN. Those events are the best one to clean/restore MediaCapture resources.
这篇关于正确清理 MediaCapture 资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!