Click here to Skip to main content
15,890,897 members
Articles / Desktop Programming / MFC
Article

Controlling Winamp2/3/Sonique Programmatically

Rate me:
Please Sign up or sign in to vote.
4.55/5 (8 votes)
11 Mar 20031 min read 71K   788   42   6
An article on controlling popular media players from external programs.

Introduction

This article shows a method of controlling Winamp 1.x-2.x, Winamp3, and Sonique 1.x, programmatically from external programs.

Background

A while back, I was a beta tester for a cool little utility called Codename: Dashboard. Basically it is a sidebar-like program that serves as a holder for sub-components.

Anyway, there was a great Windows Media Player component for it, but nothing for Winamp. After having less-than-stellar experience with MP3s and WMP 6.4, I have pretty much refused to use it as my media player. (I know… I hear WMP9 is better. Time will tell.) This prompted me to write a component for Winamp…

There’s only one problem: I cant find ANY documentation on controlling Winamp3 remotely. It seems that the Nullsoft guys left out this capability in Wasabi. So after a bit of digging, here is what I came up with.

Using the code

First off, we have to figure out what player we are running:

HWND FindPlayer(int wanted) 
{
    HWND hwnd;

    if (wanted == 0 || wanted == 4) {
        hwnd = FindWindow("Sonique Window Class", NULL);
        if (hwnd != 0) {
            playerID = 4;
            return hwnd;
        }
    }

    if (wanted == 0 || wanted == 3) {
        hwnd = FindWindow("Studio", NULL);
        if (hwnd != 0) {
            playerID = 3;
            return hwnd;
        }
    }

    if (wanted == 0 || wanted == 2) {
        hwnd = FindWindow("Winamp v1.x", NULL);
        if (hwnd != 0) {
            playerID = 2;
            return hwnd;
        }
    }

    playerID = 0;

    return 0;
}

Next we figure out which command to send:

// Winamp 2 defines
#define W2_PREV             40044
#define W2_PLAY             40045
#define W2_PAUSE            40046
#define W2_STOP             40047
#define W2_NEXT             40048
#define W2_FILEPLAY         40029 

#define W2_ISPLAYING        104
#define W2_OUTPUTTIME       105
#define W2_JUMPTOTIME       106
#define W2_SETPLAYLISTPOS   121
#define W2_GETLISTLENGTH    124
#define W2_GETLISTPOS       125
#define W2_GETINFO          126


// Winamp 3 defines
#define W3_PREV                   'z'
#define W3_PLAY                   'x'
#define W3_PAUSE                   'c'
#define W3_STOP                   'v'
#define W3_NEXT                   'b'
#define W3_FILEPLAY               'l'


// Sonique 1 defines
#define S1_PREV                  'z'
#define S1_PLAY                 'x'
#define S1_PAUSE                 'c'
#define S1_STOP                 'v'
#define S1_NEXT            'b'
#define S1_FILEPLAY        'l'

Then we send the command to the proper window:

void SendW3Key(HWND hwnd_winamp,char message)
{
    short key = VkKeyScan(message);
    UINT scancode = MapVirtualKey(key, 0);
    PostMessage(hwnd_winamp, WM_KEYDOWN, key, scancode);
    PostMessage(hwnd_winamp, WM_CHAR, key, scancode);
    PostMessage(hwnd_winamp, WM_KEYUP, key, scancode);
}

So to bring it all together, it looks something like this:

private void AmpControl_Play(void)
{
HWND hwnd_winamp = FindPlayer(0);

    if (hwnd_winamp != 0) {
        if (playerID == 2) {
            SendMessage(hwnd_winamp, WM_COMMAND, W2_PLAY, 0);
        }
        else if (playerID == 3) {
            SendW3Key(hwnd_winamp, W3_PLAY);
        }
        else if (playerID == 4) {
            SendW3Key(hwnd_winamp, S1_PLAY);
        }
    }
}

The source includes Play, Pause, Next, Previous, Open and Stop. All packaged in an easy-to-use DLL project.

History

v1.0.0.0 - 11 Mar 2003 - Initial Release

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


Written By
Web Developer
United States United States
I'm a 23 year old student/.NET Developer from Charlotte NC. I spend my free time with my wonderful wife and 2 cats. At least I would if I had any free time...

Comments and Discussions

 
GeneralMore Winamp commands Pin
AndrewSmirnov17-May-04 8:28
AndrewSmirnov17-May-04 8:28 
#define WINAMP_FILE_QUIT 40001
#define WINAMP_OPTIONS_PREFS 40012
#define WINAMP_OPTIONS_AOT 40019
#define WINAMP_FILE_REPEAT 40022
#define WINAMP_FILE_SHUFFLE 40023
#define WINAMP_HIGH_PRIORITY 40025
#define WINAMP_FILE_PLAY 40029
#define WINAMP_OPTIONS_EQ 40036
#define WINAMP_OPTIONS_ELAPSED 40037
#define WINAMP_OPTIONS_REMAINING 40038
#define WINAMP_OPTIONS_PLEDIT 40040
#define WINAMP_HELP_ABOUT 40041
#define WINAMP_MAINMENU 40043
#define WINAMP_BUTTON1 40044
#define WINAMP_BUTTON2 40045
#define WINAMP_BUTTON3 40046
#define WINAMP_BUTTON4 40047
#define WINAMP_BUTTON5 40048
#define WINAMP_VOLUMEUP 40058
#define WINAMP_VOLUMEDOWN 40059
#define WINAMP_FFWD5S 40060
#define WINAMP_REW5S 40061
#define WINAMP_NEXT_WINDOW 40063
#define WINAMP_OPTIONS_WINDOWSHADE 40064
#define WINAMP_BUTTON1_SHIFT 40144
#define WINAMP_BUTTON2_SHIFT 40145
#define WINAMP_BUTTON3_SHIFT 40146
#define WINAMP_BUTTON4_SHIFT 40147
#define WINAMP_BUTTON5_SHIFT 40148
#define WINAMP_BUTTON1_CTRL 40154
#define WINAMP_BUTTON2_CTRL 40155
#define WINAMP_BUTTON3_CTRL 40156
#define WINAMP_BUTTON4_CTRL 40157
#define WINAMP_BUTTON5_CTRL 40158
#define WINAMP_OPTIONS_DSIZE 40165
#define IDC_SORT_FILENAME 40166
#define IDC_SORT_FILETITLE 40167
#define IDC_SORT_ENTIREFILENAME 40168
#define IDC_SELECTALL 40169
#define IDC_SELECTNONE 40170
#define IDC_SELECTINV 40171
#define IDM_EQ_LOADPRE 40172
#define IDM_EQ_LOADMP3 40173
#define IDM_EQ_LOADDEFAULT 40174
#define IDM_EQ_SAVEPRE 40175
#define IDM_EQ_SAVEMP3 40176
#define IDM_EQ_SAVEDEFAULT 40177
#define IDM_EQ_DELPRE 40178
#define IDM_EQ_DELMP3 40180
#define IDC_PLAYLIST_PLAY 40184
#define WINAMP_FILE_LOC 40185
#define WINAMP_OPTIONS_EASYMOVE 40186
#define WINAMP_FILE_DIR 40187
#define WINAMP_EDIT_ID3 40188
#define WINAMP_TOGGLE_AUTOSCROLL 40189
#define WINAMP_VISSETUP 40190
#define WINAMP_PLGSETUP 40191
#define WINAMP_VISPLUGIN 40192
#define WINAMP_JUMP 40193
#define WINAMP_JUMPFILE 40194
#define WINAMP_JUMP10FWD 40195
#define WINAMP_JUMP10BACK 40197

GeneralPlugin needed for using WM_COMMAND, WM_USER and WM_COPYDATA stuff Pin
Lars [Large] Werner12-May-03 0:09
professionalLars [Large] Werner12-May-03 0:09 
GeneralPretty Cool Idea... Pin
Joel Holdsworth12-Mar-03 10:32
Joel Holdsworth12-Mar-03 10:32 
GeneralRe: Pretty Cool Idea... Pin
Trollslayer11-Aug-05 10:51
mentorTrollslayer11-Aug-05 10:51 
GeneralRe: Pretty Cool Idea... Pin
Joel Holdsworth11-Aug-05 10:58
Joel Holdsworth11-Aug-05 10:58 
GeneralRe: Pretty Cool Idea... Pin
Trollslayer11-Aug-05 21:57
mentorTrollslayer11-Aug-05 21:57 

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.