The plot thickens..
I remembered my '
stop after next' script, which utilized the on play event..
Code: Select all
'==========================================================================
'
' MediaMonkey Script
'
' NAME: Stop After Current
' DESCRIPTION: adds 2 icons to the standard toolbar, to stop and pause
' after the current song finishes'
' VERSION: 1.0
' DATE : July 16, 2007
' AUTHOR: Teknojnky
'
' INSTALL:
' - Copy script to MM directory scripts\auto
'
' TODO:
'
'
'==========================================================================
'
Option Explicit
'Public StopAfterTBB
'Public PauseAfterTBB
Sub OnStartUp()
Do While Not SDB.IsRunning
SDB.ProcessMessages
Loop
' add toolbar icons for pause after, and stop after, on the player toolbar
' add separater'
SDB.UI.AddMenuItemSep SDB.UI.Menu_TbStandard,0,0
' toggle pause button'
Dim PauseAfterTBB : Set PauseAfterTBB = SDB.UI.AddMenuItem(SDB.UI.Menu_TBStandard,0,0)
PauseAfterTBB.Caption = SDB.Localize("Pauses play after currently playing song")
PauseAfterTBB.OnClickFunc = "PauseAfter"
PauseAfterTBB.UseScript = Script.ScriptPath
PauseAfterTBB.IconIndex = 2
SDB.Objects("PauseAfterTBB") = PauseAfterTBB
' toggle stop button'
Dim StopAfterTBB : Set StopAfterTBB = SDB.UI.AddMenuItem(SDB.UI.Menu_TBStandard,0,0)
StopAfterTBB.Caption = SDB.Localize("Stops play after currently playing song")
StopAfterTBB.OnClickFunc = "StopAfter"
StopAfterTBB.UseScript = Script.ScriptPath
StopAfterTBB.IconIndex = 3
SDB.Objects("StopAfterTBB") = StopAfterTBB
End Sub
Sub PauseAfter(PauseAfterTBB)
Script.UnRegisterAllEvents
If PauseAfterTBB.Checked = False Then
PauseAfterTBB.Checked = True
SDB.Objects("StopAfterTBB").Checked = False
Call Script.RegisterEvent(SDB, "OnPlay", "DoAfter")
ElseIf PauseAfterTBB.Checked = True Then
PauseAfterTBB.Checked = False
End If
End Sub
Sub StopAfter(StopAfterTBB)
Script.UnRegisterAllEvents
If StopAfterTBB.Checked = False Then
StopAfterTBB.Checked = True
SDB.Objects("PauseAfterTBB").Checked = False
Call Script.RegisterEvent(SDB, "OnPlay", "DoAfter")
ElseIf StopAfterTBB.Checked = True Then
StopAfterTBB.Checked = False
End If
' SDB.Player.Stop
End Sub
Sub DoAfter()
Script.UnRegisterAllEvents
If SDB.Objects("PauseAfterTBB").Checked = True Then
SDB.Player.Pause
ElseIf SDB.Objects("StopAfterTBB").Checked = True Then
SDB.Player.Stop
End If
msgbox ("did onplay event really unregister?")
SDB.Objects("PauseAfterTBB").Checked = False
SDB.Objects("StopAfterTBB").Checked = False
End Sub
I thought I would have to re-write the script based on the unregister not working for onplay..
but the above msgbox only appears once... meaning the event somehow got unregistered..
so I tried the script.UnregisterAllEvents in the test script..
Code: Select all
Dim testSDB : set testSDB = SDB
Sub OnStartup
dim testbutton : set testbutton = sdb.ui.addmenuitem(sdb.ui.Menu_TBStandard,0,0)
testbutton.caption = "Test"
testbutton.usescript = script.scriptpath
testbutton.onclickfunc = "testtoggle"
End Sub
Sub testtoggle(arg)
if arg.checked = false then
arg.checked = true
script.registerevent testSDB, "OnPlay", "TestOnPlay"
Else
arg.checked = false
script.unregisterevents testSDB
set testSDB = Nothing
script.UnregisterAllEvents
End If
End Sub
Sub TestOnPlay
msgbox("testonplay called")
End Sub
And still the testonplay was called.
so then I tried to create an object 'testSDB' = SDB.. that way I could unregister that testSDB and even set it to nothing.. and that did not work either..
so now, I have 2 different scripts which register and un register the same event and only one script works..
very odd..