Click here to Skip to main content
15,868,016 members
Articles / Desktop Programming / MFC

CWinamp - More than Just a Winamp2 API Wrapper

Rate me:
Please Sign up or sign in to vote.
4.86/5 (16 votes)
13 Mar 20034 min read 153.5K   2.1K   66   27
Winamp2 API wrapper with extra functions

Sample Image - winamp2api.gif

Introduction

Programmers are lazy, we all know that. Whenever we come across some API, we want to make a wrapper for it in order to use it more easily. Microsoft wrote its "Foundation Classes", and every day, someone posts an article about his own new wrapper class here on CodeProject.com. I have also decided to do so.

I needed to control my Winamp2 from another app, and after doing some research, I finally found the fine Winamp2 API documentation. But after a few minutes, I was tired of typing all those SendMessages with a number as parameter that no one on earth would want to remember. After playing around with the official Winamp2 API, I had to discover that the API doesn't provide some handy functions such like getting the current volume. So what now? Well, I began writing the wrapper. Soon I started Spy++ to get access to some handy but undocumented API calls, e.g. reading the volume or generating a HTML playlist. Woohoo! Now I felt it was time to share my work with you. :-)

My main goal was to keep the wrapper simple as possible, so that even beginners would have no problems using it. The result is one single header-file that needs to be included to your workspace. No more! Now let's start, I'll explain the most important steps and functions.

Using the winamp2 Wrapper Class

Using this class is easy as can be. Just #include "winamp2.h" to your workspace. Next, create our wrapper class variable somewhere in your project:

CWinamp amp // create the wrapper variable named "amp"

Before you can use all the functions, you need to FindWinamp(). For most people, it safe enough to call this function without any parameters. Winamp can be opened with a different window class but the standard "Winamp v1.x" by starting it with the parameter /CLASS. But most people don't do so, so you don't have to worry about the FindWindow() parameter. The function returns true, if Winamp has been found. Now you are ready to use all the nifty functions.

There are so many functions that I don't want to explain them all in detail. These are probably the most important ones:

C++
void    Previous();
void    Next();
void    Play();
void    Pause();
void    Stop();
const char* GetCurrentTitle()

Should be self-explanatory I hope :-) So if you want to go to the next track, just call the Next() function like that:

C++
CWinamp amp;
if(amp.FindWinamp())
{
    // Winamp has been found, play next track
    amp.Next();
}

The functions all have names that explain what they do, e.g. TrackGetPositionMSec(). This returns the track's current position in milliseconds. There are three functions that need to be discussed a bit more in detail, but actually they are easy to use as well. The functions are as follows:

C++
int GetVolume();
void SetVolume(int volume);
int EQGetData(int band);
void EQSetData(int band, int value);
int EQGetPreampValaue();

The GetVolume() functions return a value between 0 and 255. 0 means volume turned off completely (i.e. silent), whereas 255 means full volume. This way, you can pass a value of 0 to 255 to SetVolume(). EQGetData(int band) takes a value of 0-9 as parameter, representing one of the ten bands of the equalizer. It returns a value between 0 and 63. 0 means a value of -20 dB and 63 a value of +20 dB. Consider this, if you want to represent the value by e.g. a CSliderCtrl, make sure to set its range like that: SetRange(0, 63). To set the value of a specific band, call EQSetData(). The first parameter is the band (0-9), the second the value in the range from 0-63.

Note: For some reason, Winamp does NOT refresh the equalizer bars during runtime, but the changes are applied. You need to RestartWinamp() to make the changes visible in the equalizer. Blame the programmers of winamp ;-) EQGetPreampValaue() also returns the preamp value in the range of 0-63.

Conclusion

I'd say this is everything you need to know in order to understand the class. If you have any further questions, feel free to post a comment or send me a mail. The class has been successfully tested with Winamp 2.81.

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below. A list of licenses authors might use can be found here.



Comments and Discussions

 
Questioncan u guide me i am new for mixer control Pin
rajneshmalik30-Aug-07 2:23
rajneshmalik30-Aug-07 2:23 
GeneralBuild problems Pin
rich_dave22-Feb-06 6:51
rich_dave22-Feb-06 6:51 
GeneralRe: Build problems Pin
User 665822-Feb-06 23:44
User 665822-Feb-06 23:44 
QuestionIs it possible to set the output device? Pin
Hyun-Chul Lee6-Nov-05 20:09
Hyun-Chul Lee6-Nov-05 20:09 
AnswerRe: Is it possible to set the output device? Pin
User 66587-Nov-05 3:41
User 66587-Nov-05 3:41 
Generalwhy din't you. .. . Pin
gamitech27-Dec-04 11:19
gamitech27-Dec-04 11:19 
wrote a plug-in for winamp it would have been much easier but anyway the program is good

gabby
GeneralMissing: EQ On-off Pin
mg123427-Nov-04 16:48
mg123427-Nov-04 16:48 
GeneralRe: Missing: EQ On-off Pin
User 665829-Nov-04 2:10
User 665829-Nov-04 2:10 
GeneralRe: Missing: EQ On-off Pin
Anonymous30-Nov-04 20:57
Anonymous30-Nov-04 20:57 
GeneralRe: Missing: EQ On-off Pin
User 66581-Dec-04 8:03
User 66581-Dec-04 8:03 
QuestionAny ideea for web broadcast? Pin
stealth kid8-Sep-03 0:19
stealth kid8-Sep-03 0:19 
GeneralBug getting song title Pin
Mav Rossi7-Jul-03 21:27
Mav Rossi7-Jul-03 21:27 
GeneralRe: Bug getting song title Pin
User 665826-Jul-03 11:24
User 665826-Jul-03 11:24 
GeneralUpdate to GetCurrentTitle-bug! Pin
User 665826-Jul-03 13:18
User 665826-Jul-03 13:18 
GeneralRe: Update to GetCurrentTitle-bug! Pin
Mav Rossi27-Jul-03 21:55
Mav Rossi27-Jul-03 21:55 
GeneralRe: Update to GetCurrentTitle-bug! Pin
User 665828-Jul-03 1:21
User 665828-Jul-03 1:21 
GeneralA wrapper for Version 3 Pin
Nitromouse19-Mar-03 0:21
Nitromouse19-Mar-03 0:21 
GeneralRe: A wrapper for Version 3 Pin
User 665819-Mar-03 5:44
User 665819-Mar-03 5:44 
GeneralRe: A wrapper for Version 3 Pin
Nitromouse19-Mar-03 6:48
Nitromouse19-Mar-03 6:48 
GeneralRe: A wrapper for Version 3 Pin
Lars [Large] Werner22-Jun-03 11:45
professionalLars [Large] Werner22-Jun-03 11:45 
QuestionCurrent track path? Pin
shao_lo18-Mar-03 7:21
shao_lo18-Mar-03 7:21 
AnswerRe: Current track path? Pin
Monstroplante26-May-04 0:29
Monstroplante26-May-04 0:29 
GeneralAn Alternative Pin
jakesher15-Mar-03 5:36
jakesher15-Mar-03 5:36 
GeneralRe: An Alternative Pin
User 665815-Mar-03 6:47
User 665815-Mar-03 6:47 
GeneralCool! Pin
Ravi Bhavnani14-Mar-03 18:20
professionalRavi Bhavnani14-Mar-03 18:20 

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.