Sample Event Handlers script

From MediaMonkey Wiki
Jump to: navigation, search
' This script shows how to use COM events in MediaMonkey scripting. 
' You can associate event with a VB procedure and cancel the association later. 
 
Sub OnStartup 
  Script.RegisterEvent SDB, "OnShutdown", "SDBShutdown" 
  Script.RegisterEvent SDB, "OnTrackProperties", "SDBTrackProperties" 
  Script.RegisterEvent SDB, "OnPlay", "SDBPlay" 
  Script.RegisterEvent SDB, "OnPause", "SDBPause" 
  Set Tmr = SDB.CreateTimer( 10000)   ' Pop up a message in 10 seconds 
  Script.RegisterEvent Tmr, "OnTimer", "TestTimer" 
End Sub 
 
Sub SDBTrackProperties( tracks) 
  SDB.MessageBox "Wow, track properties were modified for "&tracks.count&" track(s)!", mtInformation, Array(mbOk) 
'  Script.UnregisterEvents SDB 
End Sub 
 
Sub SDBShutdown 
  SDB.MessageBox "MediaMonkey is finishing... :(", mtInformation, Array(mbOk) 
End Sub 
 
Sub SDBPlay 
  SDB.MessageBox "Started playback of "&SDB.Player.CurrentSong.ArtistName&_ 
    " - "&SDB.Player.CurrentSong.Title, mtInformation, Array(mbOk) 
End Sub 
 
Sub SDBPause 
  If SDB.Player.isPaused Then 
    SDB.MessageBox "Playback paused", mtInformation, Array(mbOk) 
  End If 
End Sub 
 
Sub TestTimer( Timer) 
  SDB.MessageBox "10 seconds elapsed!", mtInformation, Array(mbOk) 
  Script.UnregisterEvents Timer  ' Terminate usage of this timer 
End Sub

As of MediaMonkey 4, events can also be received by external programs. See this example, using Python.