首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Windows MediaCapture API捕获“纯音频”?

如何使用Windows MediaCapture API捕获“纯音频”?
EN

Stack Overflow用户
提问于 2012-09-10 21:26:32
回答 1查看 2.1K关注 0票数 2

我正在尝试通过Windows MediaCapture API捕获“仅音频”。我使用了下面的代码,但是得到了一个异常(HRESULT: 0xC00D36D5)。

代码语言:javascript
复制
    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();

或者请建议一个更好的方法。

EN

回答 1

Stack Overflow用户

发布于 2013-01-09 14:24:35

我正在尝试做一些类似的事情,这是我在MSDN/Samples中发现的……

代码语言:javascript
复制
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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12352725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档