This project has moved and is read-only. For the latest updates, please go here.

Streaming MP3 problem

Jul 1, 2011 at 4:06 AM
Edited Jul 1, 2011 at 4:18 AM

hi , 

I want to play a Streaming audio from the Internet.

here is code




Imports System.Net

Imports NAudio.CoreAudioApi

Imports NAudio.Wave

Imports NAudio

Public Class Form1

  Dim DwonloadDataThread As New Threading.Thread(AddressOf downloadStream)

    Dim PlayBackThread As New Threading.Thread(AddressOf Playback)

    Dim waveOut As WaveOut

    Dim bwp As New BufferedWaveProvider(New WaveFormat())

    Private Sub Playback()
        While Me.bwp.BufferLength < 65535


        End While
        Dim WaveOutDevice As IWavePlayer = New DirectSoundOut(100)
        While WaveOutDevice.PlaybackState = PlaybackState.Playing


        End While
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



    End Sub

    Private Sub downloadStream()

        Dim httpreq As HttpWebRequest = HttpWebRequest.Create("")

        Dim resp As HttpWebResponse = httpreq.GetResponse
        While True

            Dim mStream As IO.Stream = resp.GetResponseStream
            'Dim fs As New IO.FileStream("D:\a.mp3", IO.FileMode.Create)
            Dim buffer(4095) As Byte
            While True

                Dim read As Integer = mStream.Read(buffer, 0, buffer.Length)
                If read = 0 Then

                    Exit While

                End If

                Me.bwp.AddSamples(buffer, 0, read)

                'fs.Write(buffer, 0, read)

            End While

        End While    End Sub

End Class




It will not play smoothly and just like cannot find the radio frequency. 

How to improve my code?

Thanks for any help in advance.

Jul 1, 2011 at 8:28 AM

look in the latest source code at the NAudio demo for an example of how to play streaming MP3 from the internet

Jul 2, 2011 at 1:10 PM

Thank you very much!! :)

i've done the job!

Jul 6, 2011 at 4:00 PM
markheath wrote:

look in the latest source code at the NAudio demo for an example of how to play streaming MP3 from the internet

hi , 


I encounter another problem in decompressing mp3 frame.

I use both of AcmMp3FrameDecompressor and DmoMp3FrameDecompressor.

Some of computer can decompress the mp3 frame by both of them or either of them , but few of computer cannot decompress it .

would you please tell me how can i solve this problem?

Thank you very much!!

Jul 6, 2011 at 8:24 PM

you'll have to show the exception details for me to help