Click here to Skip to main content
15,881,092 members
Articles / Programming Languages / C#
Article

A Winamp Front-End Library with C#

Rate me:
Please Sign up or sign in to vote.
3.30/5 (12 votes)
8 Dec 2005CPOL5 min read 89.7K   2.3K   27   17
An article on a C# library responsible for acting as a Winamp front-end
Demo screenshot - demoScreenshot.png

Introduction

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. 

Background

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:
    1. The "wa_ipc.h" header file located in the Winamp SDK
    2. This header file
  • Methods "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;

  1. WM_COMMAND
  2. WM_USER (might be also known as WM_WA_IPC)

The first type of command is used for the main Winamp operation that has to do with its primary functionalities; such as Play(), Stop(), 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:

C#
// To tell Winamp that we are sending it a WM_COMMAND it needs the hex code 0x111
const int WM_COMMAND = 0x111; 

// To tell Winamp that we are sending it a WM_USER (WM_WA_IPC) 
// it needs the hex code 0x0400
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:

  1. Right-click on your C# project (in the Solution Explorer window) and click on the "Add Reference..." menu item
  2. From the "Add Reference" dialog, click on the "Browse" button (after you make sure that you are on the .NET tab)
  3. 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
  4. If you've done everything right, you should now be presented with the dialog box below. If you are, then hit "OK":

Add Reference screenshot- AddReference.jpg

Now just add the relevant namespace in your using section and you are ready to go:

C#
// Do not forget to include the necessary namespace
using WinampFrontEndLib;

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:

C#
private string DisplaySong()
{
    return WinampLib.GetCurrentSongTitle();
}

private void button1_Click(object sender, System.EventArgs e)
{
    WinampLib.Play();
    this.lblTitle.Caption = this.DisplaySong();
} 

The same goes with the click events of the volume up/down buttons in the demo:

C#
private void button6_Click(object sender, System.EventArgs e)
{
    WinampLib.VolumeUp();
}

private void button3_Click(object sender, System.EventArgs e)
{
    WinampLib.VolumeDown();
}

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

  1. 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.
  2. 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.
  3. 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.

History

  • 8th December, 2005 - Version 1.0

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Cyprus Cyprus
Simpsons' fanatic.

Comments and Discussions

 
QuestionShuffle & Repeat Pin
Stoyan Peev7-Aug-11 13:23
Stoyan Peev7-Aug-11 13:23 
AnswerRe: Shuffle & Repeat Pin
Stoyan Peev8-Aug-11 2:44
Stoyan Peev8-Aug-11 2:44 
GeneralTrack Position & Track Length Pin
BigManitu23-Jun-10 10:17
BigManitu23-Jun-10 10:17 
AnswerGetCurrentVolume Pin
Tsuushin31-May-09 18:15
Tsuushin31-May-09 18:15 
GeneralRe: GetCurrentVolume Pin
cybie042-Jun-09 10:08
cybie042-Jun-09 10:08 
Hey wow!

I was trying to find that myself for a few days now.

Thank you Tsuushin!
GeneralExtending Winamp library Pin
sfsdfd13-Aug-08 11:28
sfsdfd13-Aug-08 11:28 
GeneralRe: Extending Winamp library Pin
Polis Pilavas13-Aug-08 20:40
Polis Pilavas13-Aug-08 20:40 
QuestionHow to use it as an embedded player? Pin
Ibrahim Dwaikat13-Nov-07 2:39
Ibrahim Dwaikat13-Nov-07 2:39 
AnswerRe: How to use it as an embedded player? Pin
Ibrahim Dwaikat14-Nov-07 13:43
Ibrahim Dwaikat14-Nov-07 13:43 
GeneralSendMessageA Pin
hega724-Feb-07 8:09
hega724-Feb-07 8:09 
GeneralActiveWinamp Pin
fs_Death1-Feb-07 21:23
fs_Death1-Feb-07 21:23 
Newsreading the winamp playlist Pin
fs_Death31-Jan-07 10:33
fs_Death31-Jan-07 10:33 
GeneralRe: reading the winamp playlist Pin
#andy26-Jul-07 0:32
#andy26-Jul-07 0:32 
Generalwinamp plugin on own app Pin
dsovino27-Jan-07 12:23
dsovino27-Jan-07 12:23 
GeneralOr you could use the C# Winamp SDK from sourceforge Pin
FBKK3-Apr-06 1:33
FBKK3-Apr-06 1:33 
GeneralRe: Or you could use the C# Winamp SDK from sourceforge Pin
ABlokha7721-Jun-07 1:19
ABlokha7721-Jun-07 1:19 
GeneralRe: Or you could use the C# Winamp SDK from sourceforge Pin
FBKK21-Jun-07 1:29
FBKK21-Jun-07 1:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.