首页 > 解决方案 > 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

标签: c#uwphololens

解决方案


您可以尝试在 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;

如果尝试此解决方案后仍然无法正常工作,请随时反馈。


推荐阅读