c# - MediaCapture.PrepareLowLagRecordToStorageFileAsync() 在 HoloLens 上引发“类未注册”异常
问题描述
我目前正在开展一个项目,通过标准的 UWP 应用程序在 HoloLens 上录制音频。我曾经MediaCapture.PrepareLowLagRecordToStorageFileAsync()
这样做过。它在 PC 上运行良好,但是,当我将它部署到 HoloLens 上时,应用程序中断并Exception
显示“类未注册”消息。
有谁知道如何解决这个问题?
编辑:在错误的上下文中添加代码:
// Create the Media Encoding Profile we are going to use
var mediaEncodingProfile = MediaEncodingProfile.CreateFlac(AudioEncodingQuality.High);
mediaEncodingProfile.Audio.ChannelCount = 1;
// Create the file to store the recording in
var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
var audioRecordingFile = await localFolder.CreateFileAsync("audio.mp3", CreationCollisionOption.GenerateUniqueName);
// Prepare for recording
mediaRecording = await mediaCapture.PrepareLowLagRecordToStorageFileAsync
(
mediaEncodingProfile,
audioRecordingFile
);
// Begin recording
await mediaRecording.StartAsync();
抛出异常的详细信息:
System.Exception
HResult=0x80040154
Message=Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
Source=System.Private.CoreLib
StackTrace:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at UwpMediaStream.MainPage.<dictationToggleGcp_Click>d__39.MoveNext() in D:\Users\xecli\Documents\Git\uwp-media-streaming-sample\UwpMediaStream\Pages\MainPage.xaml.cs:line 601
编辑:在使用的进一步测试中MediaCapture.StartRecordToStorageFileAsync()
,我似乎在以下调用堆栈中遇到了同样的错误:
System.Exception
HResult=0x80040154
Message=Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
Source=System.Private.CoreLib
StackTrace:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at UwpMediaStream.MainPage.<dictationToggleGcp_Click>d__39.MoveNext() in D:\Users\xecli\Documents\Git\uwp-media-streaming-sample\UwpMediaStream\Pages\MainPage.xaml.cs:line 596
解决方案
您可以尝试在 HoloLens 上以 WMA 格式录制音频。我在基本相机应用程序示例中进行了一些更改,以调用MediaEncodingProfile.CreateWma(AudioEncodingQuality)
录制音频的方法。一切都按预期工作。
这是我从第 411 行更改的代码:
var voiceFile = await _captureFolder.CreateFileAsync("SimpleVoice.wma", CreationCollisionOption.GenerateUniqueName);
var encodingProfile = MediaEncodingProfile.CreateWma(AudioEncodingQuality.Auto);
//encodingProfile.Video.Properties.Add(RotationKey, PropertyValue.CreateInt32(rotationAngle));
//encodingProfile.Audio.ChannelCount = 1;
如果尝试此解决方案后仍然无法正常工作,请随时反馈。
推荐阅读
- imagemagick - 如何强制 imagemagick 保持图像的原始色彩空间
- garbage-collection - 为什么需要 gc,我们可以在没有内存安全的情况下编写语言吗?
- android - Spinner 不会显示字符串条目
- swift - Swift:在任务完成之前调用 DispatchGroup 通知
- regex - 寻找 0.1 到 24 之间的正则表达式模式。需要允许 2 个小数位
- java - 如何从 I/O 文件 Java 中编辑特定单词
- .net-core - log4net 在 .NET Core 3.1 上运行正常吗?
- swift - FileManager 会抛出什么错误?
- sql - 列出组合和它们在 SQL 中重复的次数
- python - 使用 Python 进行 BigQuery 的基本文本挖掘和 ETL