Copyright © 2005-2023 MultiMedia Soft

Events for Visual Basic 6 COM interoperability

Previous pageReturn to chapter overviewNext page

Visual Basic 6 results unreliable when dealing with delegates and callbacks in general so, when using the API in conjunctions with this development environment, a set of COM compatible events is provided.

 

In order to enable the usage of the provided events you need to invoke the COMEventEnable method, for each type of event you are going to manage, immediately after initializing the API through the InitSoundSystem method, then you need to manually enter the event management routine.

 

Inside the snippet below you can see a management example of events generated by the player through the OnPlayersEvents event handler and by an eventual casting session through the OnCastingEvents event handler; the text of a label is modified when player's monitored events are reported and the VB6 Immediate window is updated when casting events are caught:

 

Visual Basic 6

 

' declare the API

Dim WithEvents m_audioDJ As AudioDjStudioApi.AudioDjStudioApiObj

 

Private Sub m_audioDJ_OnPlayersEvents(ByVal nEvent As enumPlayerEvents, ByVal nPlayer As Integer, _

       ByVal nData1 As Long, ByVal nData2 As Long, ByVal fData3 As Single, _

       ByVal pBufferUnicode As Long, ByVal nBufferLength As Long)

   Select Case nEvent

       Case enumPlayerEvents.enumPlayerEvents_EV_SOUND_PLAYING

           labelCurrentStatus.Caption = "Sound playing..."

 

       Case enumPlayerEvents.enumPlayerEvents_EV_SOUND_PAUSED

           labelCurrentStatus.Caption = "Sound paused"

 

       Case enumPlayerEvents.enumPlayerEvents_EV_SOUND_STOPPED

           labelCurrentStatus.Caption = "Sound stopped"

         

       Case enumPlayerEvents.enumPlayerEvents_EV_SOUND_DONE

           labelCurrentStatus.Caption = "Sound playback completed"

   End Select

End Sub

 

Private Sub m_audioDJ_OnCastingEvents(ByVal nEvent As enumCastingEvents, ByVal nCastingUniqueId As Long, _

       ByVal nData1 As Long, ByVal nData2 As Long, ByVal pBufferUnicode As Long, ByVal nBufferLength As Long)

   Select Case nEvent

       Case enumCastingEvents.enumCastingEvents_EV_CASTING_LOOPBACK_START

           Debug.Print "Casting started"        

       Case enumCastingEvents.enumCastingEvents_EV_CASTING_LOOPBACK_STOP

           Debug.Print "Casting stopped"        

       Case enumCastingEvents.enumCastingEvents_EV_CASTING_WMA_CLIENT_CONNECT

           Debug.Print "Client connected"        

   End Select

End Sub

 

Private Sub Form_Load()

  ' instance the API

   Set m_audioDJ = New AudioDjStudioApi.AudioDjStudioApiObj

     

  ' init the control

   m_audioDJ.InitSoundSystem 1, 0, 0, 0, 0

 

  ' enable player and casting events for COM clients like VB6

   m_audioDJ.COMEventEnable enumEventTypes_EVENT_TYPE_PLAYER

   m_audioDJ.COMEventEnable enumEventTypes_EVENT_TYPE_CASTING

 

  ' load a sound file and start playback

   m_audioDJ.LoadSound 0, "c:\mysound.mp3"

   m_audioDJ.PlaySound 0

 

  ... do other stuffs

 

End Sub

 

 

as seen for regular ActiveX controls, the name of the event management routine is made of a number of parts: the name of the component (in this case "m_audioDJ" which was originally declared with the "WithEvents" attribute) followed by the underscore "_" character and by the name of the event (in this case "OnPlayersEvents") and related parameters.