PDA

View Full Version : Problem telling Winamp to play a file in Delphi


MrPuzzled
4th May 2002, 08:32
Hi,

I'm wanting to tell Winamp to play a file/add a file to the playlist in Delphi. Has anyone got a reliable Procedure to do this?
I do have this, which came from a freeware component to control winamp:

procedure AddMp3ToPlayList(mp3ToAdd:string);
Var
x : integer;
begin
Mp3ToAdd:=MP3ToAdd+#0;
GethWnd_WinAmp;
for x:=0 to Length(MP3ToAdd) do
PostMessage(hwnd_winamp,wm_user,ord(mp3toadd[x]),IPC_PLAYFILE);
// also crashes if I comment the line below out
PostMessage(hwnd_winamp,wm_user,0,IPC_PLAYFILE);
end;

But this unfortunately works when adding the first time, for some weird reason it causes Winamp to crash with "This application performed an illegal operation", on tryiing to add a second file.

Thanks

MrPuzzled
4th May 2002, 08:34
IPC_PLAYFILE = 100;

by the way :)

Gourou
4th May 2002, 13:17
maybe your problem is the use of PostMessage, instead of SendMessage? I dunno, that seems strange behavior, it's hard to determine it when it works one time and not another. BTW, I dont know if you can, but try stepping through your code and checking out the values you get, see if maybe something is failing. if you pass 0 to one of those, that could be it.

henryt
25th May 2002, 16:39
Well, all I can give you is this piece of C++ code. But I think you can translate it into Delphi-Pascal.


bool __fastcall TWinamp::AddSong(AnsiString File)
{
typedef struct {
char file[MAX_PATH];
int index;
} fileinfo;

COPYDATASTRUCT cds;
fileinfo f;

HWND hwndWinamp = FindWindow("Winamp v1.x",NULL);
HWND hwndWinampPlaylist = FindWindow("Winamp PE",NULL);

if(hwndWinampPlaylist && hwndWinamp)
{
cds.dwData = 106;
strcpy(f.file, File.c_str()); // Path to the new entry

// Get # of Songs, add file to the end of current playlist
f.index = SendMessage(hwndWinamp, WM_USER, 0, 124) + 1;

cds.lpData = (void *)&f;
cds.cbData = sizeof(fileinfo);
SendMessage(hwndWinampPlaylist ,WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds);

// select inserted song
SendMessage(hwndWinamp,WM_USER, f.index, 121);

//now start playing
SendMessage(hwndWinamp,WM_COMMAND, 40045, 0);

return true;
}
return false;
}