cmnetworx Posted May 31, 2010 Share Posted May 31, 2010 (edited) Ok, So I have put together a script based off of some documentation on this site and examples, etc. I have it functioning to some extent, but I know I have something wrong with it.. Here is the code #include <IE.au3> #include <Winamp.au3> $oWinAmp = _WinampCreate ("") If @error Then Exit $bAttached = @extended $oEvent = ObjEvent($oWinAmp, "_Event_") $oPlayList = $oWinAmp.playlist While 1 Sleep(100) WEnd Func _PopMessage($message) $v = _IEAttach ("Yahoo") $v.document.parentwindow.execscript("show_alert('" & $message & "')") EndFunc Func _Event_ChangedTrack() $oItem = $oPlayList ($oPlayList.position) ; $oWinAmp.Pause Sleep(200) _PopMessage('The next song is ' & $oItem.Title & ' by ' & $oItem.Artist) Sleep(2000) ; $oWinAmp.Play EndFunc ;==>_Event_ChangedTrack I am trying to get it to attach to an already existing winamp task, and also an already running IE window with the title Yahoo, then when the track changes in winamp (playlist) it kicks a javascript to the browser, that is contained in the page.. I can get it to work randomely, Sometimes it kicks out the info twice, then sometimes nothing at all.. Either way when the track changes the script closes with this error C:\Program Files\AutoIt3\Include\IE.au3 (3754) : ==> Variable must be of type "Object".: $IEComErrorScriptline = $oIEErrorHandler.scriptline $IEComErrorScriptline = $oIEErrorHandler^ ERROR ->00:28:45 AutoIT3.exe ended.rc:1 and I can't figure out what Im doin wrong here.. ------------------ I got a bit further now Part of the problem was the PopMessage script was redeclaring IEAttach, and fouling up the script, I now have #include <IE.au3> #include <Winamp.au3> $v = _IEAttach ("Yahoo") $oWinAmp = _WinampCreate ("") If @error Then Exit $bAttached = @extended $oEvent = ObjEvent($oWinAmp, "_Event_") $oPlayList = $oWinAmp.playlist While 1 Sleep(100) WEnd Func _PopMessage($message) $v.document.parentwindow.execscript("show_alert('" & $message & "')") EndFunc Func _Event_ChangedTrack() $oItem = $oPlayList ($oPlayList.position) ; $oWinAmp.Pause Sleep(200) _PopMessage('The next song is ' & $oItem.Title & ' by ' & $oItem.Artist) Sleep(2000) ; $oWinAmp.Play EndFunc ;==>_Event_ChangedTrack It is now allowing the script to run in a loop, but for some reason it is popping up the alert multiple times.. Is there a way to prevent it from sending the message twice? like a value that is set after the message has been sent, but resets after a couple of seconds (In case the track changes again?) Any help would be appreciated. Thanks Edited May 31, 2010 by cmnetworx Link to comment Share on other sites More sharing options...
jaberwacky Posted May 31, 2010 Share Posted May 31, 2010 (edited) This is your entire script, correct?Also, I've noticed that this line has an incomplete function name: $oEvent = ObjEvent($oWinAmp, "_Event_")Should it be?:$oEvent = ObjEvent($oWinAmp, "_Event_ChangedTrack") Edited May 31, 2010 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 31, 2010 Share Posted May 31, 2010 (edited) Also, I've noticed that this line has an incomplete function name: $oEvent = ObjEvent($oWinAmp, "_Event_")Should it be?:$oEvent = ObjEvent($oWinAmp, "_Event_ChangedTrack")No. Look closer at the example in the help file under ObjEvent(). The prefix is "_Event_", and that will be appended with the name of the event that occurs to find the handling function (if it exists, you don't have to handle every possible event). So you might do this event registration only once, but have several handling functions for the different events you are interested in, like _Event_ChangedTrack(), _Event_Play() and _Event_End().P.S. Why did you resurrect an 18-month old topic?Was looking at "Joined" date. Doh! I plead insufficient caffeination! Edited May 31, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 31, 2010 Share Posted May 31, 2010 P.S. Why did you resurrect an 18-month old topic?Looks like 5 hours to me .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
cmnetworx Posted June 1, 2010 Author Share Posted June 1, 2010 Thanks for the input. I am wondering though, Does anybody know why it sometimes fires the javascript twice? I placed in a few sleep entries to slow it up, and hopefully prevent it from firing twice.. which it sometimes still does.. Is there a way to have it set a value like $notified = 1; after it sends the show_alert command, then reset that value to 0 after the song changes? That way I could use an if else statement? Yeah, it is the full script, feel free to use it if you'd like, You'll want to change the show_alert('" & $message & "') to alert('" & $message & "') as I built in show_alert onto the page and intend to have it slide in a message, etc. and the window title of course also. Link to comment Share on other sites More sharing options...
jaberwacky Posted June 1, 2010 Share Posted June 1, 2010 $v.document.parentwindow.execscript("show_alert('" & $message & "')") Isn't show_alert a javascript function that pops up a messagebox? Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
zorphnog Posted June 1, 2010 Share Posted June 1, 2010 Based on your error, you are definitely receiving a COM error and it's not being handled. The problem is that the IE and Winamp UDF libraries are competing for the COM error handler. AutoIt only allows you to register one COM error handler. Try this and see if you are able to catch the error:expandcollapse popup#include <IE.au3> #include <Winamp.au3> $oMyErrorHandler = ObjEvent("AutoIt.Error", "_MyErrorHandler") $oWinAmp = _WinampCreate ("") If @error Then Exit $bAttached = @extended $oEvent = ObjEvent($oWinAmp, "_Event_") $oPlayList = $oWinAmp.playlist While 1 Sleep(100) WEnd Func _PopMessage($message) $v = _IEAttach ("Yahoo") $v.document.parentwindow.execscript("show_alert('" & $message & "')") EndFunc Func _Event_ChangedTrack() $oItem = $oPlayList ($oPlayList.position) ; $oWinAmp.Pause Sleep(200) _PopMessage('The next song is ' & $oItem.Title & ' by ' & $oItem.Artist) Sleep(2000) ; $oWinAmp.Play EndFunc ;==>_Event_ChangedTrack Func _MyErrorHandler() $sOutput = "" $sOutput &= "--> COM Error Encountered in " & @ScriptName & @CR $sOutput &= "----> ErrorScriptline = " & $oMyErrorHandler.scriptline & @CR $sOutput &= "----> ErrorNumberHex = " & $oMyErrorHandler.number & @CR $sOutput &= "----> ErrorNumber = " & Hex($oMyErrorHandler.number, 8) & @CR $sOutput &= "----> ErrorWinDescription = " & StringStripWS($oMyErrorHandler.description, 2) & @CR $sOutput &= "----> ErrorDescription = " & StringStripWS($oMyErrorHandler.WinDescription, 2) & @CR $sOutput &= "----> ErrorSource = " & $oMyErrorHandler.Source & @CR $sOutput &= "----> ErrorHelpFile = " & $oMyErrorHandler.HelpFile & @CR $sOutput &= "----> ErrorHelpContext = " & $oMyErrorHandler.HelpContext & @CR $sOutput &= "----> ErrorLastDllError = " & $oMyErrorHandler.LastDllError & @CR ConsoleWrite($sOutput) EndFunc ;==>_MyErrorHandler Link to comment Share on other sites More sharing options...
cmnetworx Posted June 6, 2010 Author Share Posted June 6, 2010 Sorry for the delay in response, I have changed my script some since you pointed out the two libraries are most likely conflicting.. and inserted the error handler, However I am not catching anything.. and it is still repeating the announcement twice (or in this case it runs ie_jscript twice)#include <Winamp.au3> $oMyErrorHandler = ObjEvent("AutoIt.Error", "_MyErrorHandler") $oWinAmp = _WinampCreate ("") If @error Then Exit $bAttached = @extended $oEvent = ObjEvent($oWinAmp, "_Event_") $oPlayList = $oWinAmp.playlist While 1 Sleep(100) WEnd Func _Event_ChangedTrack() $oItem = $oPlayList ($oPlayList.position) Sleep(200) Run('ie_jscript.exe show_alert "' & $oItem.Title & ' - ' & $oItem.Artist& '"') Sleep(2000) EndFunc ;==>_Event_ChangedTrack Func _MyErrorHandler() $sOutput = "" $sOutput &= "--> COM Error Encountered in " & @ScriptName & @CR $sOutput &= "----> ErrorScriptline = " & $oMyErrorHandler.scriptline & @CR $sOutput &= "----> ErrorNumberHex = " & $oMyErrorHandler.number & @CR $sOutput &= "----> ErrorNumber = " & Hex($oMyErrorHandler.number, 8) & @CR $sOutput &= "----> ErrorWinDescription = " & StringStripWS($oMyErrorHandler.description, 2) & @CR $sOutput &= "----> ErrorDescription = " & StringStripWS($oMyErrorHandler.WinDescription, 2) & @CR $sOutput &= "----> ErrorSource = " & $oMyErrorHandler.Source & @CR $sOutput &= "----> ErrorHelpFile = " & $oMyErrorHandler.HelpFile & @CR $sOutput &= "----> ErrorHelpContext = " & $oMyErrorHandler.HelpContext & @CR $sOutput &= "----> ErrorLastDllError = " & $oMyErrorHandler.LastDllError & @CR ConsoleWrite($sOutput) EndFunc ;==>_MyErrorHandlerMy thought is that maybe ChangedTrack is being ran twice possibly due to leaving one track and entering another.. I am going to do some more research into the specifics of winamp.au3. I suppose the cheap trick in this scenario would be to make the script sleep for a few seconds before its able to run changedtrack again.. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now