Author Topic: [VB 2008] How to record internet radio to mp3?  (Read 5509 times)

matisek2

  • Posts: 3
Hello
I have a problem:
I found a code to record the stream from the internet but it only records 7 seconds

Please help me

This code I found:

Imports Un4seen
Imports Un4seen.Bass

Imports System.IO
Imports System.Runtime.InteropServices

Public Class Form1
    Private _fs As FileStream = Nothing
    Private _myDownloadProc As DOWNLOADPROC
    Private _data() As Byte ' local data buffer


#Region " Declarations "

    ' Declarations
    Private strm As Integer = 0 ' Our Stream
    Private RetVal As Integer = 0   ' Return Value
#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Initializes the bass object
        If False = Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle) Then
            MsgBox("BASS Init Error!")
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
        Dim CI As New Un4seen.Bass.BASS_CHANNELINFO
        Dim TI As New Un4seen.Bass.AddOn.Tags.TAG_INFO
        Dim strm As String = "http://sc-interstacja.pl:7000"
        Dim stream
        _myDownloadProc = New DOWNLOADPROC(AddressOf MyDownload)
        stream = Bass.BASS_StreamCreateURL("http://sc-interstacja.pl:7000", 0, BASSFlag.BASS_DEFAULT, _myDownloadProc, IntPtr.Zero)
        Bass.BASS_ChannelPlay(stream, False)
        Timer1.Enabled = True
    End Sub


    Private Sub MyDownload(ByVal buffer As IntPtr, ByVal length As Integer, ByVal user As IntPtr)
        If _fs Is Nothing Then
            ' create the file
            _fs = File.OpenWrite("output.mp3")
        End If

        ' increase the data buffer as needed
        If _data Is Nothing OrElse _data.Length < length Then
            _data = New Byte(length) {}
        End If
        ' copy from managed to unmanaged memory
        Marshal.Copy(buffer, _data, 0, length)
        ' write to file
        _fs.Write(_data, 0, length)

    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
        _fs.Flush()
        _fs.Close()
    End Sub
End Class

Ian @ un4seen

  • Administrator
  • Posts: 23146
Re: [VB 2008] How to record internet radio to mp3?
« Reply #1 on: 29 Nov '11 - 15:17 »
I'm not a VB.Net user myself, so I'm not sure, but your code looks like it should work. Is playback continuing beyond the 7 seconds? To confirm what is happening with it, you could try adding some logging in your "MyDownload" function; the final call would be with buffer=0 and length=0 (indicating that the download has finished).

matisek2

  • Posts: 3
Re: [VB 2008] How to record internet radio to mp3?
« Reply #2 on: 30 Nov '11 - 13:56 »
that's what do I do with the code that I have?

I'm just a beginner in BASS libraries. This is my first project with it

radio42

  • Posts: 4705
Re: [VB 2008] How to record internet radio to mp3?
« Reply #3 on: 30 Nov '11 - 15:53 »
Is this the entire code?
Are you doing anything in the Timer event?

Also note, that you should set the "_fs" member back to "Nothing" in your btnStop_Click event handler - so that the next call in your Button1_Click event handler would be successfully (re)open the file for writing.

jaromanda

  • Posts: 22
Re: [VB 2008] How to record internet radio to mp3?
« Reply #4 on: 1 Dec '11 - 12:43 »
Have you considered that the site you are ripping has some sort of anti streamripping defence to stop you from illegally ripping their stream?

Just sayin'

matisek2

  • Posts: 3
Re: [VB 2008] How to record internet radio to mp3?
« Reply #5 on: 2 Dec '11 - 18:25 »
I make radio player for this station and they wished to do the recording function