我在输入 wav 文件名并让 nAudio 接受它作为StreamMixToDisk时遇到问题。
Public Sub SetupAudio()
'Setup the Mixer
mixer = New WaveMixerStream32()
mixer.AutoStop = False
If waveOutDevice Is Nothing Then
'waveOutDevice = new AsioOut();
waveOutDevice = New WaveOut(0, 300, False)
waveOutDevice.Init(mixer)
waveOutDevice.Play()
End If
End Sub
Private Sub cmbRecordDirect_Click(sender As Object, e As EventArgs) Handles cmbRecord.Click
Dim saveFileDialog As New SaveFileDialog()
saveFileDialog.Title = "Select output file:"
saveFileDialog.Filter = "WAV Files (*.wav)|*.wav"
saveFileDialog.FileName = outputFilename
If saveFileDialog.ShowDialog() = DialogResult.OK Then
outputFilename = saveFileDialog.FileName
mixer.StreamMixToDisk(outputFilename)
mixer.StartStreamingToDisk()
cmbRecordDirect.Enabled = False
cmbStopDirect.Enabled = True
cmbPauseDirect.Enabled = True
End If
End Sub
outputFilename是c:\test.wav但是一旦它到达了mixer.StreamMixToDisk(outputFilename)就会出现错误提示:
A first chance exception of type 'System.NullReferenceException'
Object reference not set to an instance of an object.
上面转换为 VB.net 的 C# 代码是这样的:
private void cmbRecordDirect_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = "Select output file:";
saveFileDialog.Filter = "WAV Files (*.wav)|*.wav";
saveFileDialog.FileName = outputFilename;
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
outputFilename = saveFileDialog.FileName;
mixer.StreamMixToDisk(outputFilename);
mixer.StartStreamingToDisk();
cmbRecordDirect.Enabled = false;
cmbStopDirect.Enabled = true;
cmbPauseDirect.Enabled = true;
}
}
什么可能导致此错误发生?