Go Back   Winamp Forums > Developer Center > Winamp Development

Reply
Thread Tools Search this Thread Display Modes
Old 4th May 2002, 08:32   #1
MrPuzzled
Junior Member
 
Join Date: Apr 2002
Posts: 5
Problem telling Winamp to play a file in Delphi

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 is offline   Reply With Quote
Old 4th May 2002, 08:34   #2
MrPuzzled
Junior Member
 
Join Date: Apr 2002
Posts: 5
IPC_PLAYFILE = 100;

by the way
MrPuzzled is offline   Reply With Quote
Old 4th May 2002, 13:17   #3
Gourou
Senior Member
 
Gourou's Avatar
 
Join Date: Feb 2002
Location: The backside of the universe on the trailing edge of eternity
Posts: 238
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.
Gourou is offline   Reply With Quote
Old 25th May 2002, 16:39   #4
henryt
Junior Member
 
henryt's Avatar
 
Join Date: May 2002
Location: out there
Posts: 30
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;
}
henryt is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > Winamp Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump