当我按照Microsoft's article使用audiodeviceinputnode类时出现“accessdenied”错误。这是我的代码:

public sealed partial class MainPage : Page {
  private AudioGraph graph = null;
  private AudioDeviceInputNode deviceInputNode = null;

  public MainPage() {
    this.InitializeComponent();
  }

  private async Task CreateAudioGraph() {

    // Create an AudioGraph with default settings
    AudioGraphSettings settings = new AudioGraphSettings(AudioRenderCategory.Media);

    CreateAudioGraphResult result = await AudioGraph.CreateAsync(settings);

    if (result.Status != AudioGraphCreationStatus.Success) {
      // Cannot create graph
      await new ContentDialog() {
        Title = "Error",
        Content = String.Format("AudioGraph Creation Error because {0}", result.Status.ToString())
      }.ShowAsync();
      return;
    }

    graph = result.Graph;

    // Create a device input node
    CreateAudioDeviceInputNodeResult inputDeviceNodeResult = await graph.CreateDeviceInputNodeAsync(Windows.Media.Capture.MediaCategory.Other);

    if (inputDeviceNodeResult.Status != AudioDeviceNodeCreationStatus.Success) {
      // Cannot create device input node
      await new ContentDialog() {
        Title = "Error",
        Content = String.Format("DeviceInputNode Creation Error because {0}", inputDeviceNodeResult.Status.ToString()),
        PrimaryButtonText = "OK",
        IsSecondaryButtonEnabled = false
      }.ShowAsync();
      return;
    }
    deviceInputNode = inputDeviceNodeResult.DeviceInputNode;
  }

  private async void button_Click(object sender, RoutedEventArgs e) {
    await CreateAudioGraph();
  }
}

但我可以运行official sample。你知道这个问题吗?

最佳答案

我想出来了。如果要使用AudioDeviceInputNode,需要在项目中打开package.appxmanifest并选中“功能”选项卡中的“麦克风”。

10-08 08:25