Is There A Way To Stop Occurence Of The Exception "WaveStillPlaying calling waveOutWrite"?

29 views Asked by At

I am trying to create Music Player with visualizations such as wave view, spectrum view etc. When I debug the program, I get an Exception "WaveStillPlaying Calling waveOutWrite".

I checked the whole code for "MusicList_SelectedIndexChanged". Tried to stop Playback of the WaveOut and Disposed It. Then defined the AudioFileReader and initialized the WaveOut with it and started playback. But still throwing same exception. How can I avoid the exception to occur?

This Is The Code To Initialize And Play The WaveStream:

wO.Stop()
            MeteringProvider = Nothing
            SampleProvider = Nothing

            wO.Dispose()

            Try

                Dim file As TagLib.File = TagLib.File.Create(MusicPaths(MusicList.SelectedIndex))

                If (file.Tag.Pictures.Length > 0) Then
                    Dim bin = CType(file.Tag.Pictures(0).Data.Data, Byte())
                    Dim img As Drawing.Bitmap = System.Drawing.Bitmap.FromStream(New System.IO.MemoryStream(bin)).GetThumbnailImage(2500, 2500, Nothing, IntPtr.Zero)
                    Dim ico As Icon = System.Drawing.Icon.FromHandle(img.GetHicon())
                    Me.Icon = ico
                Else
                    Me.Icon = My.Resources.ICON
                End If



                Me.Text = "Music Player - " & MusicList.SelectedItem.ToString
            Catch ex As Exception
                Me.Icon = My.Resources.ICON
                Me.Text = "Music Player - " & MusicList.SelectedItem.ToString
            End Try



            If (MusicPaths(MusicList.SelectedIndex).EndsWith(".mp3")) Then
                afr = New Mp3FileReader(MusicPaths(MusicList.SelectedIndex))
            ElseIf (MusicPaths(MusicList.SelectedIndex).EndsWith(".wav")) Then
                afr = New WaveFileReader(MusicPaths(MusicList.SelectedIndex))
            ElseIf (MusicPaths(MusicList.SelectedIndex).EndsWith(".aiff")) Then
                afr = New AiffFileReader(MusicPaths(MusicList.SelectedIndex))
            End If

            MiniPlayerMode.Visible = True
            MiniPlayerMode.Enabled = True

            wO = New WaveOut()

            SampleRate = afr.WaveFormat.SampleRate



            MusicController1.MusicNumber = MusicList.SelectedIndex + 1

            MusicController1.ControlCalled = "Playback_PLAY"
            MusicController1.PlayPause.Text = ";"

            MusicController1.AudioStream = afr

            Minipanel.WaveStream = rawWave

            If (MusicList.SelectedItem.ToString().Length < 56) Then
                MusicName.Text = MusicList.SelectedItem
                Minipanel.MusicName = MusicName.Text
            Else
                Dim str As String = ""
                For C As Int32 = 0 To MusicList.SelectedItem.ToString.Length

                    If (C < 56) Then
                        str += MusicList.SelectedItem.ToString(C)
                    End If
                Next

                MusicName.Text = str & "..."

            End If

            Minipanel.MusicName = MusicName.Text


            rawWave = New RawSourceWaveStream(New IO.MemoryStream(waveData0), afr.WaveFormat) 'Using RawSourceWaveStream To Change SampleRate



            SampleProvider = New NAudio.Wave.SampleProviders.SampleChannel(rawWave)
            MeteringProvider = New NAudio.Wave.SampleProviders.MeteringSampleProvider(SampleProvider)


            wO.Init(rawWave)

            If (Spectrum_Viewer1.WaveStream IsNot Nothing) Then Spectrum_Viewer1.WaveStream.Dispose()

            Spectrum_Viewer1.WaveStream = rawWave
            Spectrum_Viewer1.StreamPosition = 0


            rawWave.Position = 0
            bfr = 0
            TrackBar1.Value = 0


            wO.Play()
0

There are 0 answers