Copyright © 2005-2018 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 simply need to invoke the COMEventsEnable method 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 an example of management of events generated by the player through the OnPlayersEvents event handler; the text of a label is modified when monitored events are reported:

 

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 Form_Load()

  ' instance the API

   Set m_audioDJ = New AudioDjStudioApi.AudioDjStudioApiObj

     

  ' init the control

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

 

  ' enable events for COM clients like VB6

   m_audioDJ.COMEventsEnable

 

  ' load a sound file and start playback

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

   m_audioDJ.PlaySound 0

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.