gpt4 book ai didi

c# - 如何使用 Windows MediaCapture API 捕获 "Audio Only"?

转载 作者:可可西里 更新时间:2023-11-01 10:07:43 27 4
gpt4 key购买 nike

我正在尝试通过 Windows MediaCapture API 捕获“仅音频”。我正在使用以下代码但出现异常(HRESULT:0xC00D36D5)。

    MediaCapture captureMgr = new MediaCapture();   
MediaCaptureInitializationSettings captureSettings = new MediaCaptureInitializationSettings();
captureSettings.StreamingCaptureMode = StreamingCaptureMode.Audio;
await captureMgr.InitializeAsync(captureSettings);
this.CaptureVideoElement.Source = captureMgr;// exception is thrown here...
await captureMgr.StartPreviewAsync();

请告诉我我做错了什么?或者请提出更好的出路。

最佳答案

我正在尝试做类似的事情,这是我通过 MSDN/示例发现的...

private async void OnStartRecordingBtnClick(object sender, RoutedEventArgs e)
{
try
{
m_mediaCaptureMgr = new MediaCapture();
var settings = new MediaCaptureInitializationSettings();
settings.StreamingCaptureMode = StreamingCaptureMode.Audio;
await m_mediaCaptureMgr.InitializeAsync(settings);

}
catch (Exception exception)
{
// Do Exception Handling
}
}

private async void OnStopRecordingBtnClick(object sender, RoutedEventArgs e)
{
try
{
String fileName;
if (!m_bRecording)
{
fileName = "audio.mp4";
m_recordStorageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName);
MediaEncodingProfile recordProfile = null;
recordProfile = MediaEncodingProfile.CreateM4a(Windows.Media.MediaProperties.AudioEncodingQuality.Auto);
await m_mediaCaptureMgr.StartRecordToStorageFileAsync(recordProfile, this.m_recordStorageFile);
m_bRecording = true;
}
else
{
await m_mediaCaptureMgr.StopRecordAsync();
m_bRecording = false;
if (!m_bSuspended)
{
var stream = await m_recordStorageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
playbackElement.AutoPlay = true;
playbackElement.SetSource(stream, this.m_recordStorageFile.FileType);
}
}
}
catch (Exception exception)
{
// Do Exception Handling...
m_bRecording = false;
}
}

希望这对您有所帮助。这是 MSDN 链接: enter link description here

关于c# - 如何使用 Windows MediaCapture API 捕获 "Audio Only"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12352725/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com