Old 4th March 2004, 06:31   #1
VbAspCppGuy
Junior Member
 
VbAspCppGuy's Avatar
 
Join Date: Jan 2002
Location: Somwhere
Posts: 32
Send a message via AIM to VbAspCppGuy
Get current song?

I am trying to make a small app that when run will get the file name of the song currently playing, then pop up a box asking if I want to delete it, if yes is chosen, winamp will switch to the next song, and the file that was playing is deleted.

Err...so I need to know how to get the currently playing file...and Im sure I can figure out how to make it go to the next song, I saw it in the SDK.

(PS: I wanna do this so I can set one of the keys on my logitech KB to run the app, I really really really need to clean my play list, and this seems to be a simple way to do it )
VbAspCppGuy is offline   Reply With Quote
Old 4th March 2004, 10:21   #2
javajunky
Senior Member
 
Join Date: Apr 2001
Posts: 269
Actually a surprisingly good idea I like it! However if I remember correctly (which I probably) don't its only possible to access information such as filenames of the current track as a plugin, not a standalone application. As a standalone application there's a message you can send to the Winamp window that returns the currently playing track name and I think track id, but I don't think you ca get the filename. I'm sure someone will correctly if I'm (no-doubt) wrong. However perhaps you could write your 'app' as a plugin in a similar fashion to the already existing hot-keys stuff so it'll respond to a key-press 'ctrl-alt-d' or something ?
javajunky is offline   Reply With Quote
Old 5th March 2004, 00:29   #3
VbAspCppGuy
Junior Member
 
VbAspCppGuy's Avatar
 
Join Date: Jan 2002
Location: Somwhere
Posts: 32
Send a message via AIM to VbAspCppGuy
Hmm thats also a good idea. I was inspired to do this cause I bought this logitech elite keyboard with all these useless buttons. But now its kind of pointless to research this cause when I open my winamp it playes for 3-8 seconds then closes.
VbAspCppGuy is offline   Reply With Quote
Old 5th March 2004, 01:41   #4
shaneh
Major Dude
 
Join Date: Jan 2004
Location: Brisbane, Australia
Posts: 1,193
code:

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "wa_ipc.h"
#include "shellapi.h"

//undoc'd API..sigh
#define IPC_PE_DELETEINDEX 104

int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
DWORD processid;
HANDLE hwaProcess;
SHFILEOPSTRUCT shfileop;
SIZE_T bread;
char filename[MAX_PATH];

HWND wa_wnd = FindWindow("Winamp v1.x", NULL );

if (wa_wnd == NULL)
return 1;

HWND pl_wnd = FindWindow("Winamp PE", NULL);
memset(filename, 0, MAX_PATH);

GetWindowThreadProcessId(wa_wnd, &processid);
hwaProcess = OpenProcess(PROCESS_VM_READ, FALSE, processid);
int pos=SendMessage(wa_wnd,WM_WA_IPC,0,IPC_GETLISTPOS);
char *name=(char*)SendMessage(wa_wnd,WM_WA_IPC,pos,IPC_GETPLAYLISTFILE);
ReadProcessMemory(hwaProcess, name, filename, MAX_PATH, &bread);
CloseHandle(hwaProcess);

if (MessageBox(wa_wnd, filename, "Skip and Delete?", MB_YESNO) == IDYES)
{
//Skip the song
SendMessage(wa_wnd,WM_COMMAND,40048,0);

//Check that playlist has advanced
int pos2=SendMessage(wa_wnd,WM_WA_IPC,0,IPC_GETLISTPOS);
//If last song, hasn't advanced, so stop instead of skip
if (pos2 == pos)
SendMessage(wa_wnd,WM_COMMAND,40047,0);

//Remove the song from playlist
SendMessage(pl_wnd,WM_WA_IPC,IPC_PE_DELETEINDEX,pos);

//Double null it for shoperation
filename[strlen(filename)+1] = '\0';

shfileop.hwnd = wa_wnd;
shfileop.pFrom = filename;
shfileop.pTo = NULL;
shfileop.wFunc = FO_DELETE;
shfileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;

//Send file to recycle bin
SHFileOperation(&shfileop);
}

return 0;
}

Attached Files
File Type: zip cleaner.zip (12.3 KB, 344 views)
shaneh is offline   Reply With Quote
Old 5th March 2004, 03:29   #5
VbAspCppGuy
Junior Member
 
VbAspCppGuy's Avatar
 
Join Date: Jan 2002
Location: Somwhere
Posts: 32
Send a message via AIM to VbAspCppGuy
Wow! Thank you very much! You went and did it all...heh. Ive never seen how to recycle bin files in C++ before, darn nifty stuff. I think ill throw in like a 250ms sleep after it skips the file so that it gives it some time to actually complete it. Ill fiddle with it all and if I make any big changes Ill post em.
VbAspCppGuy is offline   Reply With Quote
Old 5th March 2004, 03:37   #6
VbAspCppGuy
Junior Member
 
VbAspCppGuy's Avatar
 
Join Date: Jan 2002
Location: Somwhere
Posts: 32
Send a message via AIM to VbAspCppGuy
Ok....question this...where do I find shellapi.h?
VbAspCppGuy is offline   Reply With Quote
Old 5th March 2004, 06:22   #7
javajunky
Senior Member
 
Join Date: Apr 2001
Posts: 269
Well in my case : C:\program files\Microsoft Visual Studio\VC98\include ... but that should be one of the (or *the* one default include path on a VC project, so it should pick it up immediately!)
javajunky is offline   Reply With Quote
Old 5th March 2004, 14:28   #8
shaneh
Major Dude
 
Join Date: Jan 2004
Location: Brisbane, Australia
Posts: 1,193
I think the SendMessage may not return until the song is actually advanced (including the fading out of the last song).

I was originally going to put in a sleep, but, I didnt have any file locking problems, but maybe i didnt test all cross fading options.

The attached file has the compiled version.
shaneh is offline   Reply With Quote
Old 5th March 2004, 19:57   #9
VbAspCppGuy
Junior Member
 
VbAspCppGuy's Avatar
 
Join Date: Jan 2002
Location: Somwhere
Posts: 32
Send a message via AIM to VbAspCppGuy
Yeah, works great. I had a bit of trouble getting it to work right with C++ in VS2003 tho. You dont need the shellapi.h

Thanks again
VbAspCppGuy is offline   Reply With Quote
Old 6th March 2004, 01:07   #10
shaneh
Major Dude
 
Join Date: Jan 2004
Location: Brisbane, Australia
Posts: 1,193
Hmm, thats funny, Im using VS2003 and I definetly needed it. I don't need it if I strip out the #define WIN32_LEAN_AND_MEAN, because I guess windows.h then includes it.

But I guess then its not lean and mean then is it. Perhaps your project settings are wrong, just start with a blank win32 application (not console - you dont want that black screen) and add the .cpp file.
shaneh is offline   Reply With Quote
Old 30th August 2004, 13:46   #11
saivert
Banned
 
saivert's Avatar
 
Join Date: Jan 2001
Location: Norway
Posts: 927
More stuff...

You must #include "shellapi.h"!
Maybe you are using "StdAfx.h" which may included it for some reason...

And how do you get the selected item(s) in the playlist (not the current playing one). I mean those which are highlighted.
saivert is offline   Reply With Quote
Old 30th August 2004, 13:50   #12
shaneh
Major Dude
 
Join Date: Jan 2004
Location: Brisbane, Australia
Posts: 1,193
You cant. You can write a media library plugin which adds to the send to menu. And winamp will hand them to you when your item is clicked.

Or you can do an ugly windows hook hack and fake the 'playlist entry' command, and intercept the creation of the playlist entry dialog, hide it, read the entry, then destroy it. Winamp does this for every entry thats selected so it effectively gives you the selected items. if you wanna go down that route.

otherwise, you can continue to badger nullsoft to provide this api.
shaneh is offline   Reply With Quote
Old 31st August 2004, 10:05   #13
saivert
Banned
 
saivert's Avatar
 
Join Date: Jan 2001
Location: Norway
Posts: 927
Maybe faking the 'playlist entry' command, and intercepting the creation of the playlist entry dialog works, but it doesn't give you the index values. Only the filenames is returned but you can use IPC_GETPLAYLISTFILE and search for the filename in the playlist. Then you will get the index, right??
saivert is offline   Reply With Quote
Old 31st August 2004, 10:14   #14
shaneh
Major Dude
 
Join Date: Jan 2004
Location: Brisbane, Australia
Posts: 1,193
If thats what you want to do, of course it would work. But consider that could involve doing a sendmessage and strcmp for 5,000+ items in a playlist. Pretty messy.
shaneh is offline   Reply With Quote
Old 1st September 2004, 03:03   #15
shaneh
Major Dude
 
Join Date: Jan 2004
Location: Brisbane, Australia
Posts: 1,193
Note its probably easier to use IPC_CHANGECURRENTFILE on each item, then retrieve the playlist position. Still would be nice if nullsoft made an api for selection easier. Its not like the code doesnt already exist, just make the 'send to' functionality available as an API. They added special code to support gen_ml 'cause they realised it wasnt possible to do, you'd think they would have made it available to any plugin.

Anyway... I think I have worked out a much cleaner hack of getting this done, not involving hooking or hidden windows etc, or other major hacks. I'll post my findings if Im succesfful. (EDIT.. nah just some false hope.. didnt quite work the way i expected). (EDIT2: or maybe it does...

Last edited by shaneh; 1st September 2004 at 03:24.
shaneh is offline   Reply With Quote
Old 11th September 2004, 12:33   #16
kridevos
Junior Member
 
Join Date: Sep 2004
Posts: 1
Can somebody tell me with what code I can retrieve the filename or title of the song currently playing in winamp?

It has to be done from an external application!

I tried IPC_GETPLAYLISTFILE, but it returns nothing

Thanks,

Kristof De Vos
kridevos is offline   Reply With Quote
Old 12th September 2004, 00:26   #17
DrO
 
Join Date: Sep 2003
Posts: 27,873
Quote:
Originally posted by kridevos
I tried IPC_GETPLAYLISTFILE, but it returns nothing
that's because it's not designed to work from an external app (hence why it's in the 2xx range of messages which are listed as being for plugins only...

but you can work around it by using ReadProcessMemory (and there are examples in this forum...)

-daz
DrO is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast 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