Results 1 to 2 of 2

Thread: [RESOLVED] Play sound from Stream instead from File

  1. #1

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Resolved [RESOLVED] Play sound from Stream instead from File

    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:
    1. Public Sub PlayWaveFile(ByVal WaveFileName As String, ByRef Buffer() As Short, Optional ByVal SamplesPerSec As Integer = 44100)
    2.         Dim BinWriter As BinaryWriter = Nothing
    3.         Dim Filestream As FileStream = Nothing
    4.         Try
    5.             Filestream = New FileStream(WaveFileName, FileMode.Create)
    6.             'Create the writer for data.
    7.             BinWriter = New BinaryWriter(Filestream)
    8.             'Do stuff to create a real Wav-File
    9.             WaveWriteHeader(BinWriter) 'write the Header
    10.             For i As Integer = 0 To UBound(Buffer) - 1 'integrate the created Sound
    11.                 BinWriter.Write(Buffer(i))
    12.             Next i
    13.             WaveWriteHeaderEnd(BinWriter) 'write the Ending
    14.             'Dim Sound As New System.Media.SoundPlayer(BinWriter.BaseStream)
    15.             Dim Sound As New System.Media.SoundPlayer()
    16.             Sound.SoundLocation = ReplayDateiPfad + "\Ping.wav"
    17.             Sound.Play()
    18.             Sound.Dispose()
    19.             Sound = Nothing
    20.             BinWriter.Close()
    21.             Filestream.Close()
    22.         Catch ex As Exception
    23.             ErrLog_schreiben("PlayWaveFile", ex.Message, WaveFileName)
    24.         End Try
    25.     End Sub
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  2. #2

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Play sound from Stream instead from File

    Problem solved, BinWriter.BaseStream was OK, however I missed the point that its position wasn't reset to zero before handing it to the soundplayer.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width