So How do you create playlists in iTunes or add songs to a specific playlist? How do you add playlists to an ipod or even songs to it? Hopefully these code snippets will help show how to do just that. This should show you also how to add songs to any playlist and how to get the name of any devices(iPods, nanos, etc.) listed in iTunes.
Here's how to create a playlist or search through playlists
-------------------------------------------------------------
using iTunesLib;
iTunesApp itunes = new iTunesAppClass();
// create a new playList
IITUserPlaylist newPlayList = (IITUserPlaylist)itunes.CreatePlaylist("TheOldiesButGoodies");
// search for a certain playlist
IITUserPlaylist playListImSearchingFor = null;
foreach (IITPlaylist pl in itunes.LibrarySource.Playlists)
{
if(pl.Name.Equals("Butt Rock"))
{
playListImSearchingFor =(IITUserPlaylist) pl;
string songfile = @"C:\music\song.mp3";
playListImSearchingFor.AddFile(songfile); // add a song to that playlist
}
}
This show how to get songs or playlists off of your ipod and how to get ipod info like the name
-----------------------------------------------------------------------------------------------
using iTunesLib;
iTunesApp itunes = new iTunesAppClass();
IITSourceCollection _sources = itunes.Sources;
foreach(IITSource s in _sources)
{
if(s.Kind == ITSourceKind.ITSourceKindIPod)
{
Console.WriteLine("Type: " + s.Kind); // This should print out the kind, ipod, library etc
Console.WriteLine("Type: " + s.Name); // This will print out the name of your ipod
IITPlaylist l = s.Playlists.get_ItemByName(s.Name);
// this will return a playlists of all the songs on your ipod
// now you can loop through this playlist to get song info
}
}

Can you email me a source code for transfering music from itunes to my iPod using visual basic code..
i already did convert a mp3 to m4a or AAC format and manually copied it to the iPod drive with windows explorer but when look at it on the iPod i can see the music i copied.
i really need it immediately.. please give me a complete vb source code of it.. tnx
thanks for the nice colleciton of posts on the itunes SDK. they are helpful.
have you found a way to “select” albums or artists or even genres in the itunes application from the COM SDK? the reason i ask is that i would like to control itunes and, indeed, i can start playing a song or even a playlist but i have been unable to find a way to request the playback of an album or all songs related to an artist. when i request that a song start playing form a particular album, e.g.
track.Play();
or
itunes.PlayFile(”c:\music\song.mp3″);
i have not found a way to play a particular album yet. any suggestions?
thanks,
jamey
hi!
is there any posibility to get the current playing playlist? i want t set the shuffle mode on/off for the current playing playlist…
thx
Kriechi
Nice, any idea if we can rename Tracks on a CD to Track 01 + 1 until End of File?
Thanks
Anyone found a way to do this via JS code?
I want to write a web page that will automatically (on the click of a button) add a podcast to itunes - the example .JS files that come with the SDK has this line….
WScript.CreateObject(”iTunes.Application”);
what is WScript?
I got a question for whoever happens to stumble upon this post, it’s been a while since it’s been posted. Is it possible to make iTunes re-evaluate an IITTrack? By re-evaluating I mean search for a track in a playlist which yields a IITTrack, setting some properties to it, and finally re-adding it to playlist it originatined from. Neither LibraryPlaylist.AddFile(”pathtofile.mp4″) nor LibraryPlaylist.AddTrack(ref IITTrack_castdown_to_an_object) seem to be of any use. Deleting an IITTrack and adding it back to the LibraryPlaylist seems to do the trick, however this of course means also deleting any metadata along with it. Any thoughts on this?