Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Win32::OLE problem with iTunes SelectedPlaylist

13 views
Skip to first unread message

zf78...@sneakemail.com

unread,
Jan 28, 2007, 9:29:44 PM1/28/07
to

Hi,

I am trying to use the iTunes SDK to select a playlist in iTunes.
Needless to say, it isn't working :(

First, the relevant part of the documentation -- full docs here
http://developer.apple.com/sdk/itunescomsdk.html

-------
HRESULT IiTunes::CreatePlaylist ( [in] BSTR playlistName,
[out, retval] IITPlaylist ** iPlaylist
)

Creates a new playlist in the main library.

If playlistName is NULL or empty, the playlist will be created with a
default name.

Parameters:
playlistName The name of the new playlist (may be NULL or empty).
iPlaylist Returns an IITPlaylist object corresponding to the new
playlist.

Return values:
S_OK The operation was successful.
E_POINTER iPlaylist is NULL.
E_FAIL An unexpected error occurred.

-------
HRESULT IITBrowserWindow::SelectedPlaylist ( [in] VARIANT *
iPlaylist )

Sets the currently selected playlist in the Source list.


Parameters:
iPlaylist The playlist to select. This must be a VARIANT of type
VT_DISPATCH that points to an IITPlaylist.

Return values:
S_OK The operation was successful.
E_POINTER iPlaylist is NULL.
E_INVALIDARG iPlaylist is not the correct VARIANT type.
ITUNES_E_OBJECTDELETED The playlist has been deleted.
E_FAIL An unexpected error occurred.

-------
Here is the code I'm trying
===========================
use Win32::OLE;
# Create a new iTunes application object
$iTunes = new Win32::OLE("iTunes.Application", \&quit );

my $tmp_playlist = $iTunes->CreatePlaylist("Temporary Playlist $$");
# This confirms that $tmp_playlist is indeed an IITUserPlaylist
Object:
print Win32::OLE->QueryObjectType($tmp_playlist) . "\n";

my $variant = Win32::OLE::Variant->new(VT_DISPATCH|VT_BYREF,
$tmp_playlist);

# Neither one of these works...
$iTunes->BrowserWindow->{'SelectedPlaylist'} = $variant;
#$iTunes->BrowserWindow->SelectedPlaylist($variant);

# If it doesn't work, delete $tmp_playlist
if ( $iTunes->BrowserWindow->SelectedPlaylist->Name() ne
"Temporary Playlist $$" ) {
print "FAILED!\n";
$tmp_playlist->Delete();
}
quit;

sub quit
{
# This destroys the object (I hope)
undef $iTunes;
exit;
}
===========================

I'd appreciate any pointers you all might be able to provide.

BTW, if you've never written Perl scripts for iTunes, there are plenty
of examples here: http://teridon.googlepages.com/itunesscripts

TIA,
Rob

zf78...@sneakemail.com

unread,
Jan 29, 2007, 8:30:49 PM1/29/07
to

I figured it out; I had to use Win32::OLE::LetProperty as follows:

my $tmp_playlist = $iTunes->CreatePlaylist("Temporary Playlist $$");

$iTunes->BrowserWindow->LetProperty(SelectedPlaylist, $tmp_playlist);

I'm still curious WHY this works, but the other method didn't!


0 new messages