0
0

Hello,
I believed someone had problems with metacallbacks in VB.Net
when playing net-streams.
Only I don’t remember witch post it was, so I’ll hope this is the right place.
But anyway, here’s the code for VB.Net. Good luck with it.

[code:to7q06il]
Public Class Form1
Inherits System.Windows.Forms.Form

'Declare
Private Declare Function FSOUND_SetOutput Lib "fmod.dll" _
    Alias "_FSOUND_SetOutput@4" (ByVal outputtype As Integer) As Byte
Private Declare Function FSOUND_SetDriver Lib "fmod.dll" _
    Alias "_FSOUND_SetDriver@4" (ByVal driver As Integer) As Byte
Private Declare Function FSOUND_SetMixer Lib "fmod.dll" _
    Alias "_FSOUND_SetMixer@4" (ByVal mixer As Integer) As Byte
Private Declare Function FSOUND_SetBufferSize Lib "fmod.dll" _
    Alias "_FSOUND_SetBufferSize@4" (ByVal lenms As Integer) As Byte
Private Declare Function FSOUND_Init Lib "fmod.dll" _
    Alias "_FSOUND_Init@12" (ByVal mixrate As Integer, _
        ByVal maxchannels As Int32, ByVal flags As Integer) As Byte
Private Declare Function FSOUND_Close Lib "fmod.dll" _
    Alias "_FSOUND_Close@0" () As Integer
Private Declare Function FSOUND_Stream_Open Lib "fmod.dll" _
    Alias "_FSOUND_Stream_Open@16" (ByVal filename As String, _
        ByVal mode As Integer, ByVal offset As Integer, _
        ByVal length As Integer) As Integer
Private Declare Function FSOUND_Stream_Play Lib "fmod.dll" _
    Alias "_FSOUND_Stream_Play@8" (ByVal channel As Integer, _
        ByVal stream As Integer) As Integer
Private Declare Function FSOUND_Stream_Stop Lib "fmod.dll" _
    Alias "_FSOUND_Stream_Stop@4" (ByVal stream As Integer) As Byte
Private Declare Function FSOUND_Stream_SetBufferSize Lib "fmod.dll" _
        Alias "_FSOUND_Stream_SetBufferSize@4" ( _
        ByVal ms As Integer) As Byte

Private Declare Function lstrcpy Lib "kernel32" _
    Alias "lstrcpyA" ( _
        ByVal lpsz As String, _
        ByVal pt As Integer _
    ) As Integer


Private Declare Function FSOUND_Stream_Net_SetMetadataCallback Lib "fmod.dll" _
    Alias "_FSOUND_Stream_Net_SetMetadataCallback@12" ( _
        ByVal stream As Integer, ByVal callback As Integer, _
        ByVal userdata As Integer) As Byte

Private Declare Function FSOUND_Stream_Net_SetMetadataCallback Lib "fmod.dll" _
    Alias "_FSOUND_Stream_Net_SetMetadataCallback@12" ( _
        ByVal stream As Integer, ByVal callback As MetaDataCallBack, _
        ByVal userdata As Integer) As Byte

Private Delegate Function MetaDataCallBack( _
        ByVal name As Integer, ByVal value As Integer, _
        ByVal userdata As Integer) As Boolean

Const FSOUND_STREAM_NET As Integer = &H80000000
Const FSOUND_OUTPUT_DSOUND As Integer = &H2
Const FSOUND_INIT_GLOBALFOCUS As Integer = &H4
Const FSOUND_MIXER_QUALITY_AUTODETECT As Integer = &H4

Dim m_hSteam As Integer
Dim m_hChannel As Integer
Dim m_CB As MetaDataCallBack
Dim m_bRet As Boolean

Region " Windows Form Designer generated code "

Private Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
        If Not (components Is Nothing) Then
            components.Dispose()
        End If
    End If
    MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.  
'Do not modify it using the code editor.
Friend WithEvents txtURL As System.Windows.Forms.TextBox
Friend WithEvents lblURL As System.Windows.Forms.Label
Friend WithEvents cmdOpen As System.Windows.Forms.Button
Friend WithEvents cmdClose As System.Windows.Forms.Button
Friend WithEvents txtArtist As System.Windows.Forms.TextBox
Friend WithEvents txtTitle As System.Windows.Forms.TextBox
Friend WithEvents lblArtist As System.Windows.Forms.Label
Friend WithEvents lblTitle As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.txtURL = New System.Windows.Forms.TextBox
    Me.lblURL = New System.Windows.Forms.Label
    Me.cmdOpen = New System.Windows.Forms.Button
    Me.cmdClose = New System.Windows.Forms.Button
    Me.txtArtist = New System.Windows.Forms.TextBox
    Me.txtTitle = New System.Windows.Forms.TextBox
    Me.lblArtist = New System.Windows.Forms.Label
    Me.lblTitle = New System.Windows.Forms.Label
    Me.SuspendLayout()
    '
    'txtURL
    '
    Me.txtURL.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.txtURL.Location = New System.Drawing.Point(8, 24)
    Me.txtURL.Name = "txtURL"
    Me.txtURL.Size = New System.Drawing.Size(308, 20)
    Me.txtURL.TabIndex = 0
    Me.txtURL.Text = "http://207.200.96.228:80/stream/1030"
    '
    'lblURL
    '
    Me.lblURL.AutoSize = True
    Me.lblURL.Location = New System.Drawing.Point(8, 8)
    Me.lblURL.Name = "lblURL"
    Me.lblURL.Size = New System.Drawing.Size(30, 16)
    Me.lblURL.TabIndex = 1
    Me.lblURL.Text = "&URL:"
    '
    'cmdOpen
    '
    Me.cmdOpen.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.cmdOpen.FlatStyle = System.Windows.Forms.FlatStyle.System
    Me.cmdOpen.Location = New System.Drawing.Point(176, 48)
    Me.cmdOpen.Name = "cmdOpen"
    Me.cmdOpen.Size = New System.Drawing.Size(64, 24)
    Me.cmdOpen.TabIndex = 2
    Me.cmdOpen.Text = "&Open"
    '
    'cmdClose
    '
    Me.cmdClose.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.cmdClose.Enabled = False
    Me.cmdClose.FlatStyle = System.Windows.Forms.FlatStyle.System
    Me.cmdClose.Location = New System.Drawing.Point(248, 48)
    Me.cmdClose.Name = "cmdClose"
    Me.cmdClose.Size = New System.Drawing.Size(64, 24)
    Me.cmdClose.TabIndex = 3
    Me.cmdClose.Text = "&Close"
    '
    'txtArtist
    '
    Me.txtArtist.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.txtArtist.Location = New System.Drawing.Point(8, 96)
    Me.txtArtist.Name = "txtArtist"
    Me.txtArtist.ReadOnly = True
    Me.txtArtist.Size = New System.Drawing.Size(308, 20)
    Me.txtArtist.TabIndex = 4
    Me.txtArtist.Text = ""
    '
    'txtTitle
    '
    Me.txtTitle.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.txtTitle.Location = New System.Drawing.Point(8, 136)
    Me.txtTitle.Name = "txtTitle"
    Me.txtTitle.ReadOnly = True
    Me.txtTitle.Size = New System.Drawing.Size(308, 20)
    Me.txtTitle.TabIndex = 5
    Me.txtTitle.Text = ""
    '
    'lblArtist
    '
    Me.lblArtist.AutoSize = True
    Me.lblArtist.Location = New System.Drawing.Point(8, 80)
    Me.lblArtist.Name = "lblArtist"
    Me.lblArtist.Size = New System.Drawing.Size(33, 16)
    Me.lblArtist.TabIndex = 7
    Me.lblArtist.Text = "Artist:"
    '
    'lblTitle
    '
    Me.lblTitle.AutoSize = True
    Me.lblTitle.Location = New System.Drawing.Point(8, 120)
    Me.lblTitle.Name = "lblTitle"
    Me.lblTitle.Size = New System.Drawing.Size(29, 16)
    Me.lblTitle.TabIndex = 8
    Me.lblTitle.Text = "Title:"
    '
    'Form1
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(328, 166)
    Me.Controls.Add(Me.lblTitle)
    Me.Controls.Add(Me.lblArtist)
    Me.Controls.Add(Me.txtTitle)
    Me.Controls.Add(Me.txtArtist)
    Me.Controls.Add(Me.cmdClose)
    Me.Controls.Add(Me.cmdOpen)
    Me.Controls.Add(Me.lblURL)
    Me.Controls.Add(Me.txtURL)
    Me.Name = "Form1"
    Me.Text = "Form1"
    Me.ResumeLayout(False)

End Sub

End Region

Private Function myMetaDataCallBack(ByVal name As Integer, _
    ByVal value As Integer, ByVal userdata As Integer) As Boolean

    Dim szBuffer As New String("", &HFF)
    lstrcpy(szBuffer, name)
    Dim iLen As Integer = InStr(szBuffer, Chr(0)) - 1
    Dim sName As String = szBuffer.Remove(iLen, szBuffer.Length - iLen)
    lstrcpy(szBuffer, value)
    iLen = InStr(szBuffer, Chr(0)) - 1
    Dim sValue As String = szBuffer.Remove(iLen, szBuffer.Length - iLen)
    If sName.Equals("ARTIST") Then
        txtArtist.Text = sValue
    ElseIf sName.Equals("TITLE") Then
        txtTitle.Text = sValue
    End If
    Return m_bRet
End Function

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND)
    FSOUND_SetBufferSize(100)
    FSOUND_Init(44100, 1, FSOUND_INIT_GLOBALFOCUS)
End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    If (m_hSteam) Then
        FSOUND_Stream_Stop(m_hSteam)
        m_hSteam = 0
    End If
    FSOUND_Close()
End Sub

Private Sub cmdOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOpen.Click
    m_hSteam = FSOUND_Stream_Open(txtURL.Text, FSOUND_STREAM_NET, 0, 0)
    If (m_hSteam) Then
        m_CB = (AddressOf myMetaDataCallBack)
        m_hChannel = FSOUND_Stream_Play(0, m_hSteam)
        m_bRet = True
        FSOUND_Stream_Net_SetMetadataCallback(m_hSteam, m_CB, 0)
        cmdOpen.Enabled = False
        cmdClose.Enabled = True
    End If
End Sub

Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
    If (m_hSteam) Then
        m_bRet = False
        FSOUND_Stream_Stop(m_hSteam)
        m_hSteam = 0
        cmdOpen.Enabled = True
        cmdClose.Enabled = False
        txtArtist.Clear()
        txtTitle.Clear()
    End If
End Sub

End Class
[/code:to7q06il]

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.