iTuner is a WPF application with a minimal user interface. When started, iTuner presents itself as a notify icon in the Windows system tray. As iTunes playback begins, a notification window is displayed showing the current track information. Clicking the notify icon opens the dashboard panel. Right-clicking the notify icon opens a context menu of common actions.

Interesting Bits

  1. iTunesLib
  2. LyricsEngine
  3. KeyManager
  4. Notify Icon
  5. WPFness
  6. Notes


Apple was thoughtful enough to release a COM interface for iTunes; this is installed along with iTunes. Also available on their Web site is an SDK, which really just means a moderately adequate .chm help file. So once iTunes is installed, you simply need to add a reference to the iTunesLib Type Library in your project.

Starting iTunes
The first task peformed by iTuner is to determine if iTunes is active and if not then activate it. To determine if iTunes is active, we simply enumerate the processes on the system looking for the process name "iTunes". If found then we can continue. However, if iTunes is not yet active, it may take a few seconds to fully initialize it so we want to display a splash screen to entertain the user while they're waiting. The splash screen is described a bit here.

iTuner.iTunes.Controller class
The Controller class is a thin wrapper that encapsulates the an iTunesAppClass instance and provides easy binding points for our UI. Nothing fancy here, only simple C# properties and a basic implementation of INotifyPropertyChanged.

There are a couple of additional features of Controller. The lyrics discovery engine is maintained by Controller. There is also a one-second repeating timer that simply signals an OnPropertyChanged event for the current track. This drives updates for the UI, partcularlly the TrackPanel control.

iTuner.iTunes.LyricsEngine class

iTuner.KeyManager class

iTuner.TrayIcons class

WPF Stuff

blah blah


Visual Studio Project Configuration
iTuner contains some low level Win32 Interop code such as hot key registration, that does not work when hosted within the Visual Studio hosting process used for debugging. For this reason, you must disable this by modifying the project properties. In the iTuner.csproj settings, I've unchecked the Enable the Visual Studio hosting process option.
Images and Artwork
All of the image files used in the iTuner application were captured and at least moderately modified using Paint.NET. The .pdn files in the Images folder are native Paint.NET files.
Multi-Icon Executable
The iTuner.exe assembly contains its own default application icon. It also contains an icon used for the Start menu Uninstall shortcut. Embedding multiple icons in a .NET executable is a straightforward process. The first icon in this .res file will appear as the default app icon. Ed Poore wrote a nice article, more or less repeated here.
  1. Create a new Native Resource Template from the File | New dialog box
  2. Right click anywhere in the designer, and select "Add Resource..."
  3. You can, at this point, import any resources you wish to embed, but we will import some icons, so click "Import..." and select the icon files. If you wish, you can change the ID associated with the resources in the Properties window.
  4. Now, we must save the resource template as a 32-bit Resource File. This is done via File | Save As..., making sure that "32-bit Resource File (*.res)" is selected in the "Save as type" box. Save it somewhere logical, e.g., in your project's directory
  5. Open up the Application tab of the Properties page of your project.
  6. In the "Resources" group box, change the selection to point to Resource File, and browse for the resource file you just saved.
  7. Once the previous step has been completed, Visual Studio will now embed the Win32 resource into the executable when it compiles. To see the changes, simply recompile the application.

Copyright (c) 2010 Steven M. Cohn. All rights reserved.

Last edited Feb 6, 2010 at 6:02 PM by stevenmcohn, version 7


No comments yet.