This is a rather basic C# class for controlling
Winamp via the classic Win32 Message API. I guess you can say it's a front-end to
Winamp capable of supporting the most common commands one would want to implement from within a .NET enabled application.
It's been some time now that I've wanted to incorporate some basic
Winamp functionality into a C# application of mine, and the need for establishing communication between the .NET environment and
Winamp came up. I started searching the net for any available libraries or code samples, but without much luck or a completed example. I soon noticed that a Winamp SDK was made available to C developers from its official website. This was when I realized that the best option for me (in order to keep things simple for my C# application) was to translate the main part of the SDK to a C# version.
Having said all these, if you still want to "master"
Winamp through your C# application, then read on.
First of all, let me say that this is not entirely my own work, meaning that I didn't write this code from scratch. It is just a C# translation of the C version official Winamp SDK. More detailed, in order to come up with this code I used the following references:
- A rather useful Geekpedia tutorial covering all the basics for setting up the communication with
Winamp from the .NET environment
- The Winamp 5 SDK
- Some constants were also taken from:
- The "wa_ipc.h" header file located in the Winamp SDK
- This header file
GetCurrentSongTitle()" and "
IsNumeric()" were adapted from this CodeProject article
Just to give you an idea, a nice real-life example where a similar front-end is incorporated are sidebars (e.g. Google Desktop's sidebar, or DesktopSidebar). These are vertical/horizontal bars docked on any screen edge of your desktop which contain a number of customizable useful stuff; news feeds, your photos, weather information, and of course basic
Winamp/Windows Media Player control-capabilities.
Basic Introduction to Winamp Command Types
This front-end class contains only
static methods. This makes it much easier to directly call any number of methods from the class without having to construct any number of objects beforehand.
The code makes heavy use of the
Win32 Message API so the relevant DLLs are imported and used throughout the methods in the class. When it comes to the communication with Winamp, I've noticed that there are two basic categories of command types that are used in order to send and/or receive an amount of information to/from Winamp;
WM_USER (might be also known as
The first type of command is used for the main
Winamp operation that has to do with its primary functionalities; such as
Pause(), etc. They are used to send a specific command to
Winamp and return nothing back to the calling program. The second type of command is used for secondary operations able to return some basic information back to the program; such as
GetPlaybackStatus() etc. Within C#, these two command types have to be represented by a specific hex code like this:
const int WM_COMMAND = 0x111;
const int WM_WA_IPC = 0x0400;
Using the Code
The first thing to do is to locate the WinampFrontEndLib.dll library file and add it into your app's reference section. I know that most probably you've done this process a million times but yet, I feel the urge to mention how it's done:
- Right-click on your C# project (in the Solution Explorer window) and click on the "Add Reference..." menu item
- From the "Add Reference" dialog, click on the "Browse" button (after you make sure that you are on the .NET tab)
- Navigate to the folder in which you stored the source files that you downloaded from here, locate the WinampFrontEndLib.dll library file from the WinampFrontEndLib\bin\Release folder and double-click on it
- If you've done everything right, you should now be presented with the dialog box below. If you are, then hit "OK":
Now just add the relevant namespace in your
using section and you are ready to go:
Since everything in the
Winamp class is declared as
static, using its methods is quite straight-forward. The following example demonstrates the click event for the play button in the demo application:
private string DisplaySong()
private void button1_Click(object sender, System.EventArgs e)
this.lblTitle.Caption = this.DisplaySong();
The same goes with the click events of the volume up/down buttons in the demo:
private void button6_Click(object sender, System.EventArgs e)
private void button3_Click(object sender, System.EventArgs e)
I guess you pretty much figured out how easy it is to call these methods from your app by now. The same logic goes with the rest of the available methods in the class.
Using the Demo
An executable demo is also included in the zip files available for download. This is a tiny project that demonstrates the use of some of the most common Winamp commands, and the ease of calling the various methods of the library. In order to use it, there is only one prerequisite; just launch
Winamp. You can then start playing around with the demo app. (I really like watching the volume bar in
Winamp moving by itself while clicking on the Volume up/down buttons on the C# demo :)).
Current Limitations (and Possibly Future Development) of the Winamp Front-end
- The library establishes only basic communication between your application and
Winamp by sending commands to a running instance of it. What I mean is that
Winamp must be installed and running if you actually want to get this thing to work at all. So don't wonder what's going on if nothing happens when you execute any method of the library without having
Winamp running in the background.
- The current version does not include any methods for launching
Winamp if it's not already running. This can be easily done by adding a few lines of code if you want to. So please feel free to alter the code in order to suit your needs.
- The current version is also incapable of hiding a running instance of
Winamp, or whatsoever. I guess that if you manage to do so, your users could get the impression that they are actually controlling
Winamp 100% through your app.
- 8th December, 2005 - Version 1.0