Win32::OLE problem with iTunes SelectedPlaylist

Z

zf78ro002

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
 
Z

zf78ro002

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top