Click here to Skip to main content
Click here to Skip to main content
Go to top

A Winamp Front-End Library with C#

, 8 Dec 2005
Rate this:
Please Sign up or sign in to vote.
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:

// 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:

// 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:

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:

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 Smile | :) ). 

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)

Share

About the Author

Polis Pilavas
Web Developer
Cyprus Cyprus
Simpsons' fanatic.

Comments and Discussions

 
QuestionShuffle & Repeat PinmemberStoyan Peev7-Aug-11 13:23 
AnswerRe: Shuffle & Repeat PinmemberStoyan Peev8-Aug-11 2:44 
I found these functions and add them myself Smile | :)
 
First you have to add these:
const int WA_SHUFFLE = 40023;
const int WA_REPEAT = 40022;
 
And then the functions themselves:
 
public static void Shuffle()
{
    IntPtr hwnd = FindWindow(m_windowName, null);
    SendMessageA(hwnd, WM_COMMAND, WA_SHUFFLE, WA_NOTHING);
}
public static void Repeat()
{
    IntPtr hwnd = FindWindow(m_windowName, null);
    SendMessageA(hwnd, WM_COMMAND, WA_REPEAT, WA_NOTHING);
}

GeneralTrack Position & Track Length PinmemberBigManitu23-Jun-10 10:17 
AnswerGetCurrentVolume PinmemberTsuushin31-May-09 18:15 
GeneralRe: GetCurrentVolume Pinmembercybie042-Jun-09 10:08 
GeneralExtending Winamp library Pinmembersfsdfd13-Aug-08 11:28 
GeneralRe: Extending Winamp library PinmemberPolis Pilavas13-Aug-08 20:40 
QuestionHow to use it as an embedded player? PinmemberIbrahim Dwaikat13-Nov-07 2:39 
AnswerRe: How to use it as an embedded player? PinmemberIbrahim Dwaikat14-Nov-07 13:43 
GeneralSendMessageA Pinmemberhega724-Feb-07 8:09 
GeneralActiveWinamp Pinmemberfs_Death1-Feb-07 21:23 
Newsreading the winamp playlist Pinmemberfs_Death31-Jan-07 10:33 
GeneralRe: reading the winamp playlist Pinmember#andy26-Jul-07 0:32 
Generalwinamp plugin on own app Pinmemberkiweed27-Jan-07 12:23 
GeneralOr you could use the C# Winamp SDK from sourceforge PinmemberFBKK3-Apr-06 1:33 
GeneralRe: Or you could use the C# Winamp SDK from sourceforge PinmemberABlokha7721-Jun-07 1:19 
GeneralRe: Or you could use the C# Winamp SDK from sourceforge PinmemberFBKK21-Jun-07 1:29 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 8 Dec 2005
Article Copyright 2005 by Polis Pilavas
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid