Sign in to follow this  
Followers 0
cmnetworx

Notify IE of currently playing winamp song, having troubles..

8 posts in this topic

#1 ·  Posted (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 by cmnetworx

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by jaberwocky6669

Share this post


Link to post
Share on other sites

#3 ·  Posted (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().

:party:

P.S. Why did you resurrect an 18-month old topic?

Was looking at "Joined" date. Doh! :mellow:

I plead insufficient caffeination!

:P

Edited 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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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:

#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

Share this post


Link to post
Share on other sites

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  ;==>_MyErrorHandler

My 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..

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0