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
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