对于Windows 8.1应用程序,我必须录制一段视频。
我用了这个指令,它基本上起作用..。http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868171.aspx
..。但是我没有在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在所有。我发现的一切都是为了进步。
发布于 2014-11-11 15:32:20
我想说的是,正确的清洁MediaCapture是高成最重要的部分,一个照片/视频也是MSDN说的:
注意:在Windows上,音乐和媒体应用程序应该清理挂起事件处理程序中的MediaCapture对象和相关资源,并在恢复事件处理程序中重新创建它们。
当您不清理MediaCapture元素时会发生什么?-在我的例子中,当我尝试使用MediaCapture运行其他应用程序时,我的手机挂起了(例如,默认的照片应用程序)。
回到您的问题-- App.xaml.cs和VideoREc.xaml之间的连接--看看所有变量(在本例中是属性)-- MediaCapture、PreviewElement、IsRecording和IsPreviewing都是在类App中定义的--它们是为整个应用程序定义的。我怀疑VideoRec.xaml只使用在App.xaml.cs中定义的那些属性的引用。
您还应该注意,挂起/恢复事件是为整个应用程序定义的,并且在发生这种事件时它们都会被触发。这是什么时候发生的?-就在你离开你的应用程序之后(只注意调试模式--当连接到计算机时,它的工作方式没有什么不同)。更多关于MSDN中的生命周期事件的信息。这些事件是清理/恢复MediaCapture资源的最佳事件。
https://stackoverflow.com/questions/26841804
复制相似问题