Sign in to follow this  
Followers 0
death pax

Itunes Current Song

22 posts in this topic

Just a little scrap from a program I made for someone, thought I would share it, if anyone would like to improve on it, go for it ^.^

func GetCurrentItunesSong()
$oItunes = ObjCreate("iTunes.Application")
if @error then 
Msgbox (0,"Itunes","Error Getting an active Itunes Object. Error code: " & hex(@error,8))
    exit
endif
$state=$oItunes.PlayerState
if $State=1 Then
    $curtrack=$oItunes.CurrentTrack
    $Trackname=$curtrack.name
    $Artistname=$curtrack.Artist
    $Title=$ArtistName&" - "&$TrackName
endif
return $title
endfunc

Share this post


Link to post
Share on other sites



guess nobody likes it, or has no use for it.. ah well :lmao:

Share this post


Link to post
Share on other sites

nah, I used it, nice script

some people just lurk and use instead of posting


Share this post


Link to post
Share on other sites

yay :lmao:

Share this post


Link to post
Share on other sites

It may be just a scrap, but it's a useful scrap.

I expanded on it a little to show a ToolTip with the current song and another whenever the song changes.

The GetCurrentItunesSongAfterCreation function does the same thing as the other one, I just didn't want it to go through the ObjCreate function every time it was called.

Global $oItunes

$CurrentSong = GetCurrentItunesSong()
TrayTip ("Current Song", $CurrentSong, 1)
Do
    Sleep (1000)
    $NewSong = GetCurrentItunesSongAfterCreation()
    If $NewSong <> $CurrentSong Then
        $CurrentSong = $NewSong
        TrayTip ("Song Changed", $CurrentSong, 1)
    EndIf
Until Not ProcessExists ("iTunes.exe")

Func GetCurrentItunesSongAfterCreation()
    Local $Title = ""
    $state=$oItunes.PlayerState
    If $State=1 Then
        $curtrack=$oItunes.CurrentTrack
        $Trackname=$curtrack.Name
        $Artistname=$curtrack.Artist
        $Title=$ArtistName & " - " & $TrackName
    EndIf
    Return $Title
EndFunc

Func GetCurrentItunesSong()
    Local $Title = ""
    $oItunes = ObjCreate("iTunes.Application")
    If @error Then
        Msgbox (0,"iTunes","Error Getting an active iTunes Object. Error code: " & Hex (@error, 8))
        Exit
    EndIf
    $State=$oItunes.PlayerState
    If $State=1 Then
        $curtrack=$oItunes.CurrentTrack
        $Trackname=$curtrack.Name
        $Artistname=$curtrack.Artist
        $Title=$ArtistName & " - " & $TrackName
    EndIf
    Return $Title
EndFunc

Share this post


Link to post
Share on other sites

^.^ thanks green

Share this post


Link to post
Share on other sites

I actually made a program for getting the current song of winamp and putting it in a file to be read for a game(unreal).

In unreal you can set keybind to read inputs from files, so i set a keybind to exec winamp.txt. in winamp.txt, when the song changed it would write "say Currently Listening to: <SongTitle>" so whenever i pressed the key it would show what song i was listening to.

Needlessly to say, other people liked the idea but requested the functionality for itunes, thus this scrap was born. ^.^

Share this post


Link to post
Share on other sites

I tried something a while back dealing with iTunes, but I couldn't figure out all the object commands and such. But regardless, they're still fun little scripts to play with.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

one thing i couldnt get working is for the program to close the open object when itunes closes, so you dont get the annoying message from itunes and the error popping up for the script

i dont think autoit can handle the type of events that itunes throws >.> otherwise instead of constantly checking to see if titles are different, you could just wait for an event to happen(itunes throws an event when song changes), and also right before itunes exits it throws another event to allow com objects to be closed gracefully

Edited by death pax

Share this post


Link to post
Share on other sites

I also couldn't get iTunes to be embedded - it really doesn't want to get in the damn GUI.

Share this post


Link to post
Share on other sites

i liked it! ... and i played with it... ^^

#include <GUIConstants.au3>
Fileinstall("...somewhere...\itunes.jpg", @tempdir & "\itunes.jpg")
Global $oItunes
$width = 400
$height = 55
$xa = @DesktopWidth - $width - 5
$ya = @DesktopHeight - $height - 30

$CurrentSong = GetCurrentItunesSong()
show()

Hotkeyset("+!s","show")

Do
    Sleep (1000)
    $NewSong = GetCurrentItunesSongAfterCreation()
    If $NewSong <> $CurrentSong Then
        $CurrentSong = $NewSong
        show()
    EndIf
Until Not ProcessExists ("iTunes.exe")

Func GetCurrentItunesSongAfterCreation()
    Local $Title = ""
    $state=$oItunes.PlayerState
    If $State=1 Then
        $curtrack=$oItunes.CurrentTrack
        $Trackname=$curtrack.Name
        $Artistname=$curtrack.Artist
        $Title=$ArtistName & " - " & $TrackName
    EndIf
    Return $Title
EndFunc

Func GetCurrentItunesSong()
    Local $Title = ""
    $oItunes = ObjCreate("iTunes.Application")
    If @error Then
        Msgbox (0,"iTunes","Error Getting an active iTunes Object. Error code: " & Hex (@error, 8))
        Exit
    EndIf
    $State=$oItunes.PlayerState
    If $State=1 Then
        $curtrack=$oItunes.CurrentTrack
        $Trackname=$curtrack.Name
        $Artistname=$curtrack.Artist
        $Title=$ArtistName & " - " & $TrackName
    EndIf
    Return $Title
EndFunc

Func show()
$hwnd = GUICreate("Alert", $width, $height, $xa, $ya, $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
GUICtrlCreatePic(@tempdir & "\itunes.jpg",0,0,55,55)
$disp = Stringreplace($CurrentSong," - ",@crlf)
GUICtrlCreateLabel($disp, 55, 15)
GUISetBkcolor(0xFFFFFF)
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 400, "long", 0x00040008)
GUISetState()
sleep(4000)
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 400, "long", 0x00050004)
GUIDelete($hwnd)
endfunc

download with pics and stuff: http://www.gymmuenchenstein.ch/rakudave/iTunes_Alert.zip

Share this post


Link to post
Share on other sites

yeah i made something like that for my version for winamp ^.^

Share this post


Link to post
Share on other sites

I havent been able to find out how to use the windows sendmessage dll call correctly yet... maybe its not possible for autoit, so instead i just read the title of the window.

here is the source&skin

WinampToaster.zip

Share this post


Link to post
Share on other sites

I just thought I'd bring this thread back up because I've been editing my script, and I added some features to it. It still shows the traytip when the song changes, but now you can do ctrl+ up, down, left, right, or space to change the volume (up and down), the song (left and right), or pause (space). If you press ctrl+shift+space, you can get more details, including current time and total length of the song, and current volume. After using this hotkey, you don't need to press ctrl before the modifier keys (although you still can). The traytip also updates itself during the 10 seconds it shows.

HotKeySet ("+{ESC}", "quitme")
HotKeySet ("^+{SPACE}", "ShowAndDoHotkeys")
Func quitme()
    Exit
EndFunc

$oMyError = ObjEvent ("AutoIt.Error", "myerrfunc")

Func MyErrFunc()

  $HexNumber=hex($oMyError.number,8)   ; for displaying purposes
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"     & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.number is: "       & @TAB & $HexNumber              & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline )
  SetError(1) ; to check for after this function returns
Endfunc

Global $oItunes, $CurTip

$CurrentSong = GetCurrentItunesSong()
TrayTip ("Current Song", $CurrentSong, 10)
$CurTip = 1
$Timer = TimerInit ()
Do
    Sleep (1000)
    If TimerDiff ($Timer) < 10000 Then
        If $CurTip = 3 Then
            TrayTip ("Current Song", GetCurrentItunesSongAfterCreation(1), 10)
        EndIf
        HotKeySet ("^{RIGHT}", "SendEventToITunes")
        HotKeySet ("^{LEFT}", "SendEventToITunes")
        HotKeySet ("^{UP}", "SendEventToITunes")
        HotKeySet ("^{DOWN}", "SendEventToITunes")
        HotKeySet ("^{SPACE}", "SendEventToITunes")
    ElseIf TimerDiff ($Timer) >= 10000 Then
        TrayTip ("", "", 1)
        HotKeySet ("^{RIGHT}")
        HotKeySet ("^{LEFT}")
        HotKeySet ("^{UP}")
        HotKeySet ("^{DOWN}")
        HotKeySet ("^{SPACE}")
        HotKeySet ("{RIGHT}")
        HotKeySet ("{LEFT}")
        HotKeySet ("{UP}")
        HotKeySet ("{DOWN}")
        HotKeySet ("{SPACE}")
    EndIf
    $NewSong = GetCurrentItunesSongAfterCreation()
    If $NewSong <> $CurrentSong Then
        $CurTip = 2
        $CurrentSong = $NewSong
        TrayTip ("Song Changed", $CurrentSong, 10)
        $Timer = TimerInit ()
    EndIf
Until Not ProcessExists ("iTunes.exe")

Func GetCurrentItunesSongAfterCreation($ShowOtherOptions = 0)
    Local $Title = ""
    $state=$oItunes.PlayerState
    If $State=1 Then
        $curtrack=$oItunes.CurrentTrack
        $Trackname=$curtrack.Name
        $Artistname=$curtrack.Artist
        $Title=$ArtistName & " - " & $TrackName
        If $ShowOtherOptions Then
            $Time = $curtrack.Time
            $CurPos = $oITunes.PlayerPosition
            $CurPos = Int ($CurPos/60) & ":" & StringRight ("00" & Mod ($CurPos, 60), 2)
            $Title &= @CRLF & "Time: " & $CurPos & " of " & $Time & @CRLF & @CRLF & _ 
            "Volume: " & $oITunes.SoundVolume
        EndIf
    Else
        $Title = "Press Ctrl+Space to Play"
    EndIf
    Return $Title
EndFunc

Func GetCurrentItunesSong()
    Local $Title = ""
    $oItunes = ObjCreate("iTunes.Application")
    If @error Then
        Msgbox (0,"iTunes","Error Getting an active iTunes Object. Error code: " & Hex (@error, 8))
        Exit
    EndIf
    $State=$oItunes.PlayerState
    If $State=1 Then
        $curtrack=$oItunes.CurrentTrack
        $Trackname=$curtrack.Name
        $Artistname=$curtrack.Artist
        $Title=$ArtistName & " - " & $TrackName
    Else
        $Title = "Press Ctrl+Space to Play"
    EndIf
    Return $Title
EndFunc

Func SendEventToITunes()
    ControlSend ("iTunes", "", $oItunes, @HotKeyPressed)
EndFunc

Func VolumeUp()
    $oITunes.SoundVolume = $oITunes.SoundVolume + 5
EndFunc

Func VolumeDown()
    $oITunes.SoundVolume = $oITunes.SoundVolume - 5
EndFunc

Func ShowAndDoHotkeys()
    TrayTip ("Current Song", GetCurrentItunesSongAfterCreation(1), 10)
    $CurTip = 3
    $Timer = TimerInit ()
    HotKeySet ("{LEFT}", "SendEventToITunes")
    HotKeySet ("{RIGHT}", "SendEventToITunes")
    HotKeySet ("{UP}", "VolumeUp")
    HotKeySet ("{DOWN}", "VolumeDown")
    HotKeySet ("{SPACE}", "SendEventToITunes")
EndFunc

Func OnAutoItExit()
    $oITunes = 0
    HotKeySet ("^{RIGHT}")
    HotKeySet ("^{LEFT}")
    HotKeySet ("^{UP}")
    HotKeySet ("^{DOWN}")
    HotKeySet ("^{SPACE}")
    HotKeySet ("{RIGHT}")
    HotKeySet ("{LEFT}")
    HotKeySet ("{UP}")
    HotKeySet ("{DOWN}")
    HotKeySet ("{SPACE}")
EndFunc

PS - I figured it'd be a good 800th post.

Share this post


Link to post
Share on other sites

awesome! I never really needed to add control over itunes to my script, and since i dont use itunes myself, i probly never would have, but i am glad to see that my original post has inspired a few people ^.^

Share this post


Link to post
Share on other sites

Yeah I use it, and I wanted to do this before, and so now that I have their helpfile I can do it.

Share this post


Link to post
Share on other sites

just want to thank for your first script to get the trackname and artist

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