I have this Sub-Routine which save a WAV-File and also plays it.
It uses the saved WAV-File for the Soundplayer. I would like to use the Stream itself to play (using the lines that are comented), however using it like that I get an error saying "Corrupted WaveHeader". Isn't the "BinWriter.BaseStream" the same Stream that is saved as my *.WAV file?
Can anybody tell me what I'm doing wrong.
vb Code:
Public Sub PlayWaveFile(ByVal WaveFileName As String, ByRef Buffer() As Short, Optional ByVal SamplesPerSec As Integer = 44100) Dim BinWriter As BinaryWriter = Nothing Dim Filestream As FileStream = Nothing Try Filestream = New FileStream(WaveFileName, FileMode.Create) 'Create the writer for data. BinWriter = New BinaryWriter(Filestream) 'Do stuff to create a real Wav-File WaveWriteHeader(BinWriter) 'write the Header For i As Integer = 0 To UBound(Buffer) - 1 'integrate the created Sound BinWriter.Write(Buffer(i)) Next i WaveWriteHeaderEnd(BinWriter) 'write the Ending 'Dim Sound As New System.Media.SoundPlayer(BinWriter.BaseStream) Dim Sound As New System.Media.SoundPlayer() Sound.SoundLocation = ReplayDateiPfad + "\Ping.wav" Sound.Play() Sound.Dispose() Sound = Nothing BinWriter.Close() Filestream.Close() Catch ex As Exception ErrLog_schreiben("PlayWaveFile", ex.Message, WaveFileName) End Try End Sub




Reply With Quote