2017-06-23 74 views
0

我試圖播放聲音與音頻圖形,並且它無法從存儲文件創建文件輸出節點。我已檢查並且存儲文件不爲空;我得到的錯誤只是未知的錯誤,並沒有幫助UWP使用AudioGraph播放.aif文件

任何想法?

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; 
} 
+0

'string CountriesFile = @「Assets \ 909_1.aif」;''應該是'strings CountriesFile =「ms-appx:///Assets/909_1.aif」;' – AVK

+0

請問您是否可以將您的音頻文件轉換爲'。 wav','.mp3','.wna'還是別的?我猜''.aif'不支持。 –

+0

這是正確的,它是文件類型。奇怪,因爲我可以通過在項目中雙擊播放.aif。無論如何現在工作。如果你把這個解決方案放在一邊,就不要接受它。 –

回答