UWP使用AudioGraph播放.aif文件

时间:2017-06-23 17:29:15

标签: c# .net uwp

我正在尝试使用音频图形播放声音,并且无法从存储文件创建文件输出节点。我检查过,存储文件不为空;我得到的错误只是未知的错误,没有帮助

有什么想法吗?

private async void HandlePlayCommand()
{
    if (_audioGraph == null)
    {
        var settings = new AudioGraphSettings(AudioRenderCategory.Media);
        var createResults = await AudioGraph.CreateAsync(settings);
        if (createResults.Status != AudioGraphCreationStatus.Success) return;

        _audioGraph = createResults.Graph;

        var deviceResult = await _audioGraph.CreateDeviceOutputNodeAsync();
        if(deviceResult.Status != AudioDeviceNodeCreationStatus.Success) return;

        var outputNode = deviceResult.DeviceOutputNode;
       StorageFile file = await GetStorageFiles();

        var fileResult = await _audioGraph.CreateFileInputNodeAsync(file);
        if (fileResult.Status != AudioFileNodeCreationStatus.Success) return;

        var fileInputNode = fileResult.FileInputNode;

        fileInputNode.AddOutgoingConnection(outputNode);


        _audioGraph.Start();
    }
}

private async Task<StorageFile> GetStorageFiles()
{
    string CountriesFile = @"Assets\909_1.aif";
    StorageFolder InstallationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
    StorageFile file = await InstallationFolder.GetFileAsync(CountriesFile);

    return file;
}

1 个答案:

答案 0 :(得分:1)

通过测试,我担心AudioGraph.CreateFileInputNodeAsync方法目前不支持.aif格式。肯定支持的格式为.mp3.wav.wna.m4a等。所以解决方案可能会将音频文件更改为其他格式。

更多详情请参阅audio official sample