简体   繁体   中英

“AccessDenied” When Call CreateDeviceInputNodeAsync

I got "AccessDenied" error when I follow the Microsoft's article to use AudioDeviceInputNode class. Here is my code:

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();
  }
}

But I am able to run the official sample . Any idea about this issue?

I figured it out. When you want to use AudioDeviceInputNode, you need to open Package.appxmanifest in your project and check the "Microphone" in Capabilities tab.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM