Need help with accessing UpNext in iTunes though the win32::ole("iTunes.Application")

I am writing a program in Perl to access the currently playing track in iTunes for Windows and to get the next 3 songs that iTunes will play.   I have the code to get the currently playing song.  But I cannot find a way to get the next 3 songs.

I would be open to alternate languages such as Ruby if you know of a way to do this.

Here is my simple Perl code to get the current playing track.  I need help getting the next 3 songs
#!C:\Perl64\bin\perl.exe

use strict;
 use Win32::OLE;

my $iTunesApp = new Win32::OLE("iTunes.Application");
 my $track = $iTunesApp->CurrentTrack;

 print "Current Track: " . $track->Name . "\nCurrent Artist: " . $track->Artist . "\n"
LVL 4
aa-denverAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Darrell PorterEnterprise Business Process ArchitectCommented:
The COM object has a number of properties, enumerated here with examples.

I would specifically look at CurrentPlaylist to compare the CurrentTrack to determine what the next 3 tracks are, if there are three tracks left to play.

I found this by Googling for

itunes windows com object properties

I hope this helps.
0
aa-denverAuthor Commented:
Thanks for the suggestion.   I have found and downloaded the Apple SDK for Windows OLE.  At this point I need help understanding how to get the objects.  I was able to get the name of the currently playing track (as before) and the name of the currently targeted playlist (code below).  But now I am stuck trying to pull the tracks for the playlist.  I would appreciate any insight you have into using the OLE methods, objects, or hierarchy.

Here is my current code.  All of the last 3 lines produce errors (I have commented them out with #)

#!C:\Perl64\bin\perl.exe
use strict;
 use Win32::OLE;
my $iTunesApp = new Win32::OLE("iTunes.Application");
 my $track = $iTunesApp->CurrentTrack;
 print "Current Track: " . $track->Name . "\nCurrent Artist: " . $track->Artist . "\n";
 my $list = $iTunesApp->CurrentPlaylist;
 print "Current Playlist: " . $list->Name . "\n";

 #my $tracklist = $iTunesApp->SelectedTracks;
 #print "Tracks: " . $tracklist->Item . "\n";
 #Print "$tracklist" ;

Here is the output from above.
c:\itunes\iTuPlay>c:\perl64\bin\perl.exe ituplay.pl
Current Track: Blues Is My Business (And Business Is Good) _West-Coast-Swing
Current Artist: The Groove Hogs
Current Playlist: Perl test

Here are the errors when the lines are not commented out:
c:\itunes\iTuPlay>c:\perl64\bin\perl.exe ituplay.pl
String found where operator expected at ituplay.pl line 19, near "Print "$trackl
ist""
        (Do you need to predeclare Print?)
syntax error at ituplay.pl line 19, near "Print "$tracklist""
Execution of ituplay.pl aborted due to compilation errors.

Here is some information from the SDK.  I need help understanding how to use it.
IITSource::Playlists().

IITTrackCollection Interface Reference

Detailed Description
Represents a collection of track objects.
Note that collection indices are always 1-based.

You can retrieve all the tracks defined for a playlist using IITPlaylist::Tracks().

You can retrieve the currently selected track or tracks using IiTunes::SelectedTracks().

HRESULT  Count ([out, retval] long *count)
  Returns the number of tracks in the collection.
 
HRESULT  Item ([in] long index,[out, retval] IITTrack **iTrack)
  Returns an IITTrack object corresponding to the given index (1-based).
0
Darrell PorterEnterprise Business Process ArchitectCommented:
Just for completeness of answer, arrays described as being 1-based are arrays in which the first element of the array, N(), is located at the first position N(1), as opposed to zero-based arrays whose first element is located at the zeroth position, N(0).
The tracklist is a collection, or an array of elements, not a text string.  The print command has a string as an argument.
You'll note the command
print "Current Playlist: " . $list->Name . "\n";
does not generate an error, so  you do not need to pre-declare print.

For specific scripting examples of how to instantiate the objects and use them and their associated collections, you may want to review the scripts located here.  While these are written in Visual Basic Scripting, it may help you to understand what needs to be done to get the information you're looking for.

For examples in Perl, please review these scripts.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.