Kris Krause .NET Meister

"If it is fast and ugly, they will use it and curse you; if it is slow, they will not use it."
- David Cheriton, The Art of Computer Systems Performance Analysis

Wednesday, February 02, 2005

Accessing iTunes With C#

The following example dumps your entire iTunes library to the console. You need to reference the COM iTunes 1.2 Type library. Currently I am running iTunes version 4.7.1.30.

using System;

namespace PlayListExample
{
class CMain
{
[STAThread]
static void Main(string[] args)
{
iTunesLib.IiTunes app = null;

try
{

app = new iTunesLib.iTunesAppClass();

foreach (iTunesLib.IITTrack track in app.LibraryPlaylist.Tracks)
{
Console.WriteLine("Artist: {0}\nSong: {1}\nGenre: {2}\n", track.Artist, track.Name, track.Genre);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
app.Quit();

app = null;

Console.ReadLine();
}
}
}
}

Labels: ,

0 Comments:

Post a Comment

<< Home