Solved

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

Posted on 2014-10-03
3
268 Views
Last Modified: 2014-10-17
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"
0
Comment
Question by:aa-denver
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 40361434
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
 
LVL 4

Author Comment

by:aa-denver
ID: 40366640
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
 
LVL 15

Accepted Solution

by:
WalkaboutTigger earned 500 total points
ID: 40366808
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Progress
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question