“访问被拒绝”时调用 CreateDeviceInputNodeAsync
本文关键字:调用 CreateDeviceInputNodeAsync 访问被拒绝 访问 拒绝 | 更新日期: 2023-09-27 18:31:44
当我按照Microsoft的文章使用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();
}
}
但我能够运行官方样本。对这个问题有任何想法吗?
我想通了。当您想使用AudioDeviceInputNode时,您需要在项目中打开Package.appxmanifest并选中"功能"选项卡中的"麦克风"。