Events for Visual Basic 6 COM interoperability
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
labelCurrentStatus.Caption = "Sound playing..."
labelCurrentStatus.Caption = "Sound paused"
labelCurrentStatus.Caption = "Sound stopped"
labelCurrentStatus.Caption = "Sound playback completed"
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
' load a sound file and start playback
m_audioDJ.LoadSound 0, "c:\mysound.mp3"
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.