This project has moved. 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

            Threading.Thread.Sleep(100)

        End While
        Dim WaveOutDevice As IWavePlayer = New DirectSoundOut(100)
        WaveOutDevice.Init(Me.bwp)
        WaveOutDevice.Play()
        While WaveOutDevice.PlaybackState = PlaybackState.Playing

            Threading.Thread.Sleep(100)

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

        PlayBackThread.Start()

        DwonloadDataThread.Start()

    End Sub

    Private Sub downloadStream()

        Dim httpreq As HttpWebRequest = HttpWebRequest.Create("http://magi.now.in:7000/kakvkxkz2214")

        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

            'fs.Close()
        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.

Coordinator
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!!

Coordinator
Jul 6, 2011 at 8:24 PM

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