Jump to content

Variable must be of type "Object".:


 Share

Recommended Posts

Hi there,

I just updated my iTunesNumpad controller (Control iTunes using your numpad :idea:) Realy usefull when you're in games...

And I always seem to get this error from now on:

C:\Program Files (x86)\AutoIt3\Include\iTunes.au3 (74) : ==> Variable must be of type "Object".:
$iTunesApp.PlayPause
$iTunesApp^ ERROR

This is my (simple) code:

;#NoTrayIcon
#include <iTunes.au3>

Global $Origin = 100
Global $Registered = False
Global $Unregistered = False

AdlibRegister ( "checkiTunes", 1200 )

Func checkiTunes()
    ConsoleWrite ( "Checking" & @CRLF )
    If ProcessExists ( "iTunes.exe" ) Then
        If $Registered = False Then
            ConsoleWrite ( "Registering" & @CRLF )
            registerHotkeys()
        EndIf
    Else
        If $Unregistered = False Then
            ConsoleWrite ( "Unregistering" & @CRLF )
            unRegisterHotkeys()
        EndIf
    EndIf
EndFunc

Func registerHotkeys()
    ConsoleWrite ( "Registered" & @CRLF )
    HotKeySet ( "{NUMPAD0}", "iTunesMute" )
    HotKeySet ( "{NUMPAD2}", "soundDown" )
    HotKeySet ( "{NUMPAD4}", "prevSong" )
    HotKeySet ( "{NUMPAD5}", "pauzeSong" )
    HotKeySet ( "{NUMPAD6}", "nextSong" )
    HotKeySet ( "{NUMPAD8}", "soundUp" )
    $Registered = True
    $Unregistered = False
EndFunc

Func unRegisterHotkeys()
    ConsoleWrite ( "Unregistered" & @CRLF )
    HotKeySet ( "{NUMPAD0}" )
    HotKeySet ( "{NUMPAD2}" )
    HotKeySet ( "{NUMPAD4}" )
    HotKeySet ( "{NUMPAD5}" )
    HotKeySet ( "{NUMPAD6}" )
    HotKeySet ( "{NUMPAD8}" )
    $Unregistered = True
    $Registered = False
EndFunc

While 1
    Sleep ( 250 )
WEnd

Func iTunesMute()
    If _iTunes_Get_Vol ( ) = 0 Then
        _iTunes_Vol_Set ( $Origin )
    Else
        $Origin = _iTunes_Get_Vol ( )
        _iTunes_Vol_Set ( 0 )
    EndIf
EndFunc

Func soundDown()
    _iTunes_Vol_Down ( 10 )
EndFunc

Func soundUp()
    _iTunes_Vol_Up ( 10 )
EndFunc

Func nextSong()
    _iTunes_Next()
EndFunc

Func prevSong()
    _iTunes_Prev()
EndFunc

Func pauzeSong()
    _iTunes_Play_Pause()
EndFunc

BTW, it makes use of the iTunes UDF (http://www.autoitscript.com/forum/index.php?showtopic=70675)

Anyway why this error is given?

Thanks in advance,

Rawox.

Edited by Rawox
Link to comment
Share on other sites

Stupid...

Well, I wanted it to return no errors when I quit iTunes but now, when I quit iTunes it returns:

C:\Program Files (x86)\AutoIt3\Include\iTunes.au3 (18) : ==> The requested action with this object has failed.:
$Library_Playlist = $iTunesApp.LibraryPlaylist
$Library_Playlist = $iTunesApp.LibraryPlaylist^ ERROR

Fixed code:

;#NoTrayIcon
#include <iTunes.au3>

Global $Origin = 100
Global $Registered = False
Global $Unregistered = False

AdlibRegister ( "checkiTunes", 1200 )

Func checkiTunes()
    ConsoleWrite ( "Checking" & @CRLF )
    If ProcessExists ( "iTunes.exe" ) Then
        _iTunes_Start()
        If $Registered = False Then
            ConsoleWrite ( "Registering" & @CRLF )
            registerHotkeys()
        EndIf
    Else
        _iTunes_Unload ( )
        If $Unregistered = False Then
            ConsoleWrite ( "Unregistering" & @CRLF )
            unRegisterHotkeys()
        EndIf
    EndIf
EndFunc

Func registerHotkeys()
    ConsoleWrite ( "Registered" & @CRLF )
    HotKeySet ( "{NUMPAD0}", "iTunesMute" )
    HotKeySet ( "{NUMPAD2}", "soundDown" )
    HotKeySet ( "{NUMPAD4}", "prevSong" )
    HotKeySet ( "{NUMPAD5}", "pauzeSong" )
    HotKeySet ( "{NUMPAD6}", "nextSong" )
    HotKeySet ( "{NUMPAD8}", "soundUp" )
    $Registered = True
    $Unregistered = False
EndFunc

Func unRegisterHotkeys()
    ConsoleWrite ( "Unregistered" & @CRLF )
    HotKeySet ( "{NUMPAD0}" )
    HotKeySet ( "{NUMPAD2}" )
    HotKeySet ( "{NUMPAD4}" )
    HotKeySet ( "{NUMPAD5}" )
    HotKeySet ( "{NUMPAD6}" )
    HotKeySet ( "{NUMPAD8}" )
    $Unregistered = True
    $Registered = False
EndFunc

While 1
    Sleep ( 250 )
WEnd

Func iTunesMute()
    If _iTunes_Get_Vol ( ) = 0 Then
        _iTunes_Vol_Set ( $Origin )
    Else
        $Origin = _iTunes_Get_Vol ( )
        _iTunes_Vol_Set ( 0 )
    EndIf
EndFunc

Func soundDown()
    _iTunes_Vol_Down ( 10 )
EndFunc

Func soundUp()
    _iTunes_Vol_Up ( 10 )
EndFunc

Func nextSong()
    _iTunes_Next()
EndFunc

Func prevSong()
    _iTunes_Prev()
EndFunc

Func pauzeSong()
    _iTunes_Play_Pause()
EndFunc

How to not recieve that error? :idea:

Link to comment
Share on other sites

You don't need $Unregistered and $Registered, so just get rid of $Unregistered. You're also running _iTunes_Start every time your checkiTunes function runs and iTunes is running. You should also run _iTunes_Unload after you run unregisterHotKeys. Finally, you will need to reduce the timing of your adlib function, maybe around 250. Try something like this:

AdlibRegister("checkiTunes", 250)

Func checkiTunes()
    ConsoleWrite("Checking" & @CRLF)
    If ProcessExists("iTunes.exe") Then
        If Not $Registered Then
            _iTunes_Start()
            ConsoleWrite("Registering" & @CRLF)
            registerHotkeys()
        EndIf
    Else
        If $Registered Then
            ConsoleWrite("Unregistering" & @CRLF)
            unRegisterHotkeys()
            _iTunes_Unload()
        EndIf
    EndIf
EndFunc
Edited by zorphnog
Link to comment
Share on other sites

Yet another error :idea:

I tried to figure this out myself, but I don't get why it returns:

C:\Program Files (x86)\AutoIt3\Include\iTunes.au3 (288) : ==> The requested action with this object has failed.:
$iTunesApp.Quit
$iTunesApp.Quit^ ERROR

when I quit iTunes...

Link to comment
Share on other sites

It happens because the _iTunes_Unload is called after iTunes has already closed. The COM object no longer has an application to reference. You should just remove the _iTunes_Unload call all together and that should fix it. You could additionally delete the object by setting $iTunesApp = 0.

Func checkiTunes()
    ConsoleWrite("Checking" & @CRLF)
    If ProcessExists("iTunes.exe") Then
        If Not $Registered Then
            _iTunes_Start()
            ConsoleWrite("Registering" & @CRLF)
            registerHotkeys()
        EndIf
    Else
        If $Registered Then
            ConsoleWrite("Unregistering" & @CRLF)
            unRegisterHotkeys()
            $iTunesApp=0
        EndIf
    EndIf
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...