Winamp Example

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Winamp Example

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Code: Select all

; 
;  Winamp frontend/plug-in control API documentation v1.1.
;  By Justin Frankel. Updates by Christophe Thibault.
;  Ad. by Ricardo Arias for PURE BASIC (22-Sept-2001)
;  Copyright (C) 1997-2000, Nullsoft Inc.
;  
;  Introduction
;  -----------------------
;  This file describes a means to easily communicate to Winamp
;  via the classic Win32 Message API. 
; 
;  These definitions/code assume C/C++. Porting to VB/Delphi shouldn't
;  be too hard. (easy to Pure Basic!!)
;  
;  First, you find the HWND of the Winamp main window. From a plug-in
;  you can easily extract this from the plug-in structure (hMainWindow,
;  hwndParent, whatever). For external apps, use:
; 
;  HWND hwnd_winamp = FindWindow("Winamp v1.x",NULL);
; 
;  (note: I know, we're in Winamp 2.x, but it's 1.x for compatibility)
; 
;  Once you have the hwnd_winamp, it's a good idea to check the version 
;  number. To do this, you send a WM_WA_IPC message to hwnd_winamp.
;  Note that WM_WA_IPC is defined as Win32's WM_USER.
; 
;  Note that sometimes you might want to use PostMessage instead of
;  SendMessage.
; 
; 
#WM_WA_IPC= $400
; 
; *************************************************************************/
; 
#IPC_GETVERSION= 0
; 
; 
;  int version = SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_GETVERSION);
; 
;  Version will be 0x20yx for winamp 2.yx. versions previous to Winamp 2.0
;  typically (but not always) use 0x1zyx for 1.zx versions. Weird, I know.
; 
;  The basic format for sending messages to Winamp is:
;  int result=SendMessage(hwnd_winamp,WM_WA_IPC,command_data,command);
;  (for the version check, command_data is 0).
; 
; 
; 
#IPC_DELETE= 101
; 
; 
;  SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_DELETE);
; 
;  You can use IPC_DELETE to clear Winamp's internal playlist.
; 
; 
; 
#IPC_STARTPLAY= 102
; 
; 
;  SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_STARTPLAY);
; 
;  Using IPC_STARTPLAY is like hitting 'Play' in Winamp, mostly.
; 
; 
; 
#IPC_ISPLAYING= 104
; 
; 
;  int res = SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_ISPLAYING);
; 
;  IPC_ISPLAYING returns the status of playback.
;  If it returns 1, it is playing. if it returns 3, it is paused, 
;  if it returns 0, it is not playing.
; 
; 
; 
#IPC_GETOUTPUTTIME= 105
; 
; 
;  int res = SendMessage(hwnd_winamp,WM_WA_IPC,mode,IPC_GETOUTPUTTIME);
; 
;  IPC_GETOUTPUTTIME returns the position in milliseconds of the 
;  current song (mode = 0), or the song length, in seconds (mode = 1).
;  Returns -1 if not playing or error.
; 
; 
; 
#IPC_JUMPTOTIME= 106
; 
;  (requires Winamp 1.60+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,ms,IPC_JUMPTOTIME);
;  IPC_JUMPTOTIME sets the position in milliseconds of the 
;  current song (approximately).
;  Returns -1 if not playing, 1 on eof, or 0 if successful
; 
; 
; 
#IPC_WRITEPLAYLIST= 120
; 
;  (requires Winamp 1.666+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_WRITEPLAYLIST);
; 
;  IPC_WRITEPLAYLIST writes the current playlist to \\Winamp.m3u,
;  and returns the current playlist position.
;  Kinda obsoleted by some of the 2.x new stuff, but still good for when
;  using a front-end (instead of a plug-in)
; 
; 
; 
#IPC_SETPLAYLISTPOS= 121
; 
;  (requires Winamp 2.0+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,position,IPC_SETPLAYLISTPOS)
; 
;  IPC_SETPLAYLISTPOS sets the playlsit position to 'position'.
; 
; 
; 
#IPC_SETVOLUME= 122
; 
;  (requires Winamp 2.0+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,volume,IPC_SETVOLUME);
; 
;  IPC_SETVOLUME sets the volume of Winamp (from 0-255).
; 
; 
; 
#IPC_SETPANNING= 123
; 
;  (requires Winamp 2.0+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,panning,IPC_SETPANNING);
; 
;  IPC_SETPANNING sets the panning of Winamp (from 0 (left) to 255 (right)).
; 
; 
; 
#IPC_GETLISTLENGTH= 124
; 
;  (requires Winamp 2.0+)
;  int length = SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_GETLISTLENGTH);
; 
;  IPC_GETLISTLENGTH returns the length of the current playlist, in
;  tracks.
; 
; 
; 
#IPC_SETSKIN= 200
; 
;  (requires Winamp 2.04+, only usable from plug-ins (not external apps))
;  SendMessage(hwnd_winamp,WM_WA_IPC,(WPARAM)"skinname",IPC_SETSKIN);
; 
;  IPC_SETSKIN sets the current skin to "skinname". Note that skinname 
;  can be the name of a skin, a skin .zip file, with or without path. 
;  If path isn't specified, the default search path is the winamp skins 
;  directory.
; 
; 
; 
#IPC_GETSKIN= 201
; 
;  (requires Winamp 2.04+, only usable from plug-ins (not external apps))
;  SendMessage(hwnd_winamp,WM_WA_IPC,(WPARAM)skinname_buffer,IPC_GETSKIN);
; 
;  IPC_GETSKIN puts the directory where skin bitmaps can be found 
;  into  skinname_buffer.
;  skinname_buffer must be MAX_PATH characters in length.
;  When using a .zip'd skin file, it'll return a temporary directory
;  where the ZIP was decompressed.
; 
; 
; 
#IPC_EXECPLUG= 202
; 
;  (requires Winamp 2.04+, only usable from plug-ins (not external apps))
;  SendMessage(hwnd_winamp,WM_WA_IPC,(WPARAM)"vis_file.dll",IPC_EXECPLUG);
; 
;  IPC_EXECPLUG executes a visualization plug-in pointed to by WPARAM.
;  the format of this string can be:
;  "vis_whatever.dll"
;  "vis_whatever.dll,0" // (first mod, file in winamp plug-in dir)
;  "C:\\dir\\vis_whatever.dll,1" 
; 
; 
; 
#IPC_GETPLAYLISTFILE= 211
; 
;  (requires Winamp 2.04+, only usable from plug-ins (not external apps))
;  char *name=SendMessage(hwnd_winamp,WM_WA_IPC,index,IPC_GETPLAYLISTFILE);
; 
;  IPC_GETPLAYLISTFILE gets the filename of the playlist entry [index].
;  returns a pointer to it. returns NULL on error.
; 
; 
; 
#IPC_GETPLAYLISTTITLE= 212
; 
;  (requires Winamp 2.04+, only usable from plug-ins (not external apps))
;  char *name=SendMessage(hwnd_winamp,WM_WA_IPC,index,IPC_GETPLAYLISTTITLE);
; 
;  IPC_GETPLAYLISTTITLE gets the title of the playlist entry [index].
;  returns a pointer to it. returns NULL on error.
; 
; 
; 
#IPC_GETLISTPOS= 125
; 
;  (requires Winamp 2.05+)
;  int pos=SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_GETLISTPOS);
; 
;  IPC_GETLISTPOS returns the playlist position. A lot like IPC_WRITEPLAYLIST
;  only faster since it doesn't have to write out the list. Heh, silly me.
; 
; 
; 
#IPC_GETINFO= 126 
; 
;  (requires Winamp 2.05+)
;  int inf=SendMessage(hwnd_winamp,WM_WA_IPC,mode,IPC_GETINFO);
; 
;  IPC_GETINFO returns info about the current playing song. The value
;  it returns depends on the value of 'mode'.
;  Mode      Meaning
;  ------------------
;  0         Samplerate (i.e. 44100)
;  1         Bitrate  (i.e. 128)
;  2         Channels (i.e. 2)
; 
; 
; 
#IPC_GETEQDATA= 127 
; 
;  (requires Winamp 2.05+)
;  int data=SendMessage(hwnd_winamp,WM_WA_IPC,pos,IPC_GETEQDATA);
; 
;  IPC_GETEQDATA queries the status of the EQ. 
;  The value returned depends on what 'pos' is set to:
;  Value      Meaning
;  ------------------
;  0-9        The 10 bands of EQ data. 0-63 (+20db - -20db)
;  10         The preamp value. 0-63 (+20db - -20db)
;  11         Enabled. zero if disabled, nonzero if enabled.
;  12         Autoload. zero if disabled, nonzero if enabled.
; 
; 
; 
#IPC_SETEQDATA= 128
;  (requires Winamp 2.05+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,pos,IPC_GETEQDATA);
;  SendMessage(hwnd_winamp,WM_WA_IPC,value,IPC_SETEQDATA);
; 
;  IPC_SETEQDATA sets the value of the last position retrieved
;  by IPC_GETEQDATA.
; 
; 
#IPC_ADDBOOKMARK= 129
;  (requires Winamp 2.4+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,(WPARAM)file,IPC_ADDBOOKMARK);
; 
;  IPC_ADDBOOKMARK will add the specified file to the Winamp bookmark list.
; 
; 
#IPC_RESTARTWINAMP= 135
;  (requires Winamp 2.2+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_RESTARTWINAMP);
; 
;  IPC_RESTARTWINAMP will restart Winamp (isn't that obvious ? :)
; 
; 
#IPC_MBOPEN= 241
;  (requires Winamp 2.05+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_MBOPEN);
;  SendMessage(hwnd_winamp,WM_WA_IPC,(WPARAM)url,IPC_MBOPEN);
; 
;  IPC_MBOPEN will open a new URL in the minibrowser. if url is NULL, it will open the Minibrowser window.
; 
; 
#IPC_INETAVAILABLE= 242
;  (requires Winamp 2.05+)
;  val=SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_INETAVAILABLE);
; 
;  IPC_INETAVAILABLE will return 1 if the Internet connection is available for Winamp.
; 
; 
#IPC_UPDTITLE= 243
;  (requires Winamp 2.2+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_UPDTITLE);
; 
;  IPC_UPDTITLE will ask Winamp to update the informations about the current title.
; 
; 
#IPC_CHANGECURRENTFILE= 245
;  (requires Winamp 2.05+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,(WPARAM)file,IPC_CHANGECURRENTFILE);
; 
;  IPC_CHANGECURRENTFILE will set the current playlist item.
; 
; 
#IPC_GETMBURL= 246
;  (requires Winamp 2.2+)
;  char buffer[4096]; // Urls can be VERY long
;  SendMessage(hwnd_winamp,WM_WA_IPC,(WPARAM)buffer,IPC_GETMBURL);
; 
;  IPC_GETMBURL will retrieve the current Minibrowser URL into buffer.
; 
; 
#IPC_REFRESHPLCACHE= 247
;  (requires Winamp 2.2+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_REFRESHPLCACHE);
; 
;  IPC_REFRESHPLCACHE will flush the playlist cache buffer.
; 
; 
#IPC_MBBLOCK= 248
;  (requires Winamp 2.4+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,value,IPC_MBBLOCK);
; 
;  IPC_MBBLOCK will block the Minibrowser from updates if value is set to 1
; 
; 
#IPC_MBOPENREAL= 249
;  (requires Winamp 2.4+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,(WPARAM)url,IPC_MBOPENREAL);
; 
;  IPC_MBOPENREAL works the same as IPC_MBOPEN except that it will works even if 
;  IPC_MBBLOCK has been set to 1
; 
; 
#IPC_GET_SHUFFLE= 250
;  (requires Winamp 2.4+)
;  val=SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_GET_SHUFFLE);
; 
;  IPC_GET_SHUFFLE returns the status of the Shuffle option (1 if set)
; 
; 
#IPC_GET_REPEAT= 251
;  (requires Winamp 2.4+)
;  val=SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_GET_REPEAT);
; 
;  IPC_GET_REPEAT returns the status of the Repeat option (1 if set)
; 
; 
#IPC_SET_SHUFFLE= 252
;  (requires Winamp 2.4+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,value,IPC_SET_SHUFFLE);
; 
;  IPC_SET_SHUFFLE sets the status of the Shuffle option (1 to turn it on)
; 
; 
#IPC_SET_REPEAT= 253
;  (requires Winamp 2.4+)
;  SendMessage(hwnd_winamp,WM_WA_IPC,value,IPC_SET_REPEAT);
; 
;  IPC_SET_REPEAT sets the status of the Repeat option (1 to turn it on)
; 
; 
; *************************************************************************/
; 
; 
;  Some API calls tend to require that you send data via WM_COPYDATA
;  instead of WM_USER. Such as IPC_PLAYFILE:
; 
; 
#IPC_PLAYFILE= 100
; 
; 
;  COPYDATASTRUCT cds;
;  cds.dwData = IPC_PLAYFILE;
;  cds.lpData = (void *) "file.mp3";
;  cds.cbData = strlen((char *) cds.lpData)+1; // include space for null char
;  SendMessage(hwnd_winamp,WM_COPYDATA,(WPARAM)NULL,(LPARAM)&cds);
; 
;  This will play the file "file.mp3".
; 
; 
; 
; 
#IPC_CHDIR= 103
; 
; 
;  COPYDATASTRUCT cds;
;  cds.dwData = IPC_CHDIR;
;  cds.lpData = (void *) "c:\\download";
;  cds.cbData = strlen((char *) cds.lpData)+1; // include space for null char
;  SendMessage(hwnd_winamp,WM_COPYDATA,(WPARAM)NULL,(LPARAM)&cds);
; 
;  This will make Winamp change to the directory C:\\download
; 
; 
; 
; 
; *************************************************************************/
; 
; 
;  Finally there are some WM_COMMAND messages that you can use to send 
;  Winamp misc commands.
;  
;  To send these, use:
; 
;  SendMessage(hwnd_winamp, WM_COMMAND,command_name,0);
; 
; 
#WINAMP_OPTIONS_EQ=               40036 ; toggles the EQ window
#WINAMP_OPTIONS_PLEDIT=           40040 ; toggles the playlist window
#WINAMP_VOLUMEUP=                 40058 ; turns the volume up a little
#WINAMP_VOLUMEDOWN=               40059 ; turns the volume down a little
#WINAMP_FFWD5S=                   40060 ; fast forwards 5 seconds
#WINAMP_REW5S=                    40061 ; rewinds 5 seconds
; 
; // the following are the five main control buttons, with optionally shift 
; // or control pressed
; // (for the exact functions of each, just try it out)
#WINAMP_BUTTON1=                  40044
#WINAMP_BUTTON2=                  40045
#WINAMP_BUTTON3=                  40046
#WINAMP_BUTTON4=                  40047
#WINAMP_BUTTON5=                  40048
#WINAMP_BUTTON1_SHIFT=            40144
#WINAMP_BUTTON2_SHIFT=            40145
#WINAMP_BUTTON3_SHIFT=            40146
#WINAMP_BUTTON4_SHIFT=            40147
#WINAMP_BUTTON5_SHIFT=            40148
#WINAMP_BUTTON1_CTRL=             40154
#WINAMP_BUTTON2_CTRL=             40155
#WINAMP_BUTTON3_CTRL=             40156
#WINAMP_BUTTON4_CTRL=             40157
#WINAMP_BUTTON5_CTRL=             40158
; 
#WINAMP_FILE_PLAY=                40029 ; pops up the load file(s) box
#WINAMP_OPTIONS_PREFS=            40012 ; pops up the preferences
#WINAMP_OPTIONS_AOT=              40019 ; toggles always on top
#WINAMP_HELP_ABOUT=               40041 ; pops up the about box :)
; 
; 
; 
;  EOF.. Enjoy.
; 

;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;************************************* PB EXAMPLE ******************************************
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

;You need to open your winamp and then try to run this example


#ButtonGadget1 = 1
#ButtonGadget2 = 2
#ButtonGadget3 = 3
#ButtonGadget4 = 4
#ButtonGadget5 = 5
#ButtonGadget6 = 6

hwnd_winamp.l  

hwnd_winamp = FindWindow_("Winamp v1.x",0)

If hwnd_winamp = 0 
  MessageRequester("Error","Winamp are not running",0)
  End
EndIf 

;Form size  

;------------------------------------------ 
#WindowHeight =  307 
#WindowWidth =  177 

If OpenWindow(0,0,0, #WindowWidth, #WindowHeight,"Winamp Test", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
  
  
  ;CONTROLS: (GADGETS)  
  
  ;  ------------------------------------------ 
  
  ButtonGadget(1,40,50,89,25,"OPEN URL")
  ButtonGadget(2,40,80,89,25,"Mp3 Info")
  ButtonGadget(3,40,120,89,25,"Song's Lenght")
  ButtonGadget(4,40,150,89,25,"Play")
  ButtonGadget(5,40,190,89,25,"Toogle EQ")
  ButtonGadget(6,40,220,89,25,"Restart Winamp")
EndIf   

Repeat 
  EventID = WaitWindowEvent()
    
  If EventID = #PB_Event_Gadget
      
    Select EventGadget()
        
      Case 1 ; MINIBROWSER & URL
        url.s = "[url]http://www.purebasic.com[/url]"
        SendMessage_(hwnd_winamp,#WM_WA_IPC,*url,#IPC_MBOPEN)
        ;something is wrong here, because the URL window get opened
        ;but do not get the *url
        ;if anybody could tell my how to call it 
        
      Case 2 ; MP3 INFO
        SampleRate =SendMessage_(hwnd_winamp,#WM_WA_IPC,0,#IPC_GETINFO)
        BitRate =SendMessage_(hwnd_winamp,#WM_WA_IPC,1,#IPC_GETINFO)
        Channels =SendMessage_(hwnd_winamp,#WM_WA_IPC,2,#IPC_GETINFO)
        If SampleRate <> 0
          MessageRequester("Mp3 Info","Samplerate: " + Str(SampleRate) + "    Bitrate: " + Str(BitRate) + "    Channels: " + Str(Channels),0)
        Else
          MessageRequester("Error","No Song Selected",0)
        EndIf
        
        ;  Mode      Meaning
        ;  ------------------
        ;  0         Samplerate (i.e. 44100)
        ;  1         Bitrate  (i.e. 128)
        ;  2         Channels (i.e. 2)
        
      Case 3 ; SONG LENGHT
        res = SendMessage_(hwnd_winamp,#WM_WA_IPC,1,#IPC_GETOUTPUTTIME)
        minute = res/60
        seconds = res - (minute * 60)
        If seconds < 10
          second$ = "0" + Str(seconds)
        Else
          second$ = Str(seconds)
        EndIf
        time$ = Str(minute) + ":" + second$
        
        MessageRequester("lenght of the song",time$,0)
        
      Case 4 ; PLAY
        SendMessage_(hwnd_winamp,#WM_WA_IPC,0,#IPC_STARTPLAY)
        
      Case 5 ; TOOGLE EQ
        SendMessage_(hwnd_winamp,#WM_COMMAND,#WINAMP_OPTIONS_EQ,1)
        
      Case 6 ; RESTART WINAMP
        SendMessage_(hwnd_winamp,#WM_WA_IPC,0,#IPC_RESTARTWINAMP)
        
    EndSelect
  EndIf
  
  
Until EventID = #PB_Event_CloseWindow

End 

;Notes: most functions are really simple, only some C style are a little difficult
;if somebody could tell us how to use it.
;Making a PlugIn is very simple, but we need to make dlls and at this moment
;its not posible in PureBasic
;later i will post some PlugIn example if someones has interest on it
;but we need to EXPORT some dll functions to do it.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Mr.Skunk.

Great Tip, ricardo, thanks.


Mr Skunk

Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.
Great Tip, ricardo, thanks.


Mr Skunk

Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st
Thanks my friend !!

You are the one to help me with the browser problem in this example...
(you always have the right answer!!)
if you see it Mr.Skunk, its exactly the same point that gives me troubles in the DLLS... sending the pointer to an string address

Thanks
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Mr.Skunk.

Hi,

Pointers are a bit difficult when you first use them.
Let's try to explain them :

You have @ and * pointers.

First you have the "@" pointer.

"@" is used in only one way, when you want to know the address of a PB string (alphanumeric:a$ or numeric:a.l) including arrays, linked list... )....

You ALWAYS use @ pointer to retreive the PB string address.

Code: Select all

;
; Access strings with pointer
;

a$="a$ is great"

ch1$="a$="+chr(34)+"a$ is great"+chr(34)+chr(13)+chr(13)
ch1$+"Address of a$ using @a$ : "+str(@a$)+chr(13)+"It works, we have a non zero value."+chr(13)+chr(13)
ch1$+"If we PeekS(@a$), we can read : "
ch1$+Peeks(@a$)+chr(13)+chr(13)

ch2$="Now if we use the * pointer"+chr(13)+chr(13)
ch2$+"Address of a$ using *a$ : "+str(*a$)+chr(13)+"It don't work (we have address=0)"+chr(13)+chr(13)
ch2$+"So if we can't use * pointer with any String, not even with numeric values (a.l)"


MessageRequester("Using @",ch1$,0)
MessageRequester("Using *",ch2$,0) 

Then, the * pointer :

You can use it to access memory structures (which are not PB Strings).

So you use the * pointer each time the address you want to retreive is NOT the address of a PB String.


I tried to explain it in the cleariest way i could. But if you have other problems with pointers, fell free to ask...

For your minibrowser, i don't know how to pass a "(WPARAM)url" parameter to pass the url.
I made some tries and it crash all the time. If someone can help...
But if you want to retreive address of url.s, you have to use... @url.s

Hope it can help you.


Mr Skunk

Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Thanks Mr Skunk

I hope that we can find some way (or some one could help) to send pointers in the WPARAM
verleihnix
User
User
Posts: 13
Joined: Sun Dec 14, 2008 4:55 am
Location: Switzerland

Re: Winamp Example

Post by verleihnix »

Hello all,

i am trying to load and play a file in Winamp. according to the example its:

#IPC_PLAYFILE= 100
;
;
COPYDATASTRUCT cds;
cds.dwData = IPC_PLAYFILE;
cds.lpData = (void *) "file.mp3";
cds.cbData = strlen((char *) cds.lpData)+1; // include space for null char
SendMessage(hwnd_winamp,WM_COPYDATA,(WPARAM)NULL,(LPARAM)&cds);
;
; This will play the file "file.mp3".
;

the conversion from its original C code to Purebasic has not successfully completed. i am trying with the following code:

#IPC_PLAYFILE= 100
Define cds.COPYDATASTRUCT
cds.COPYDATASTRUCT
cds\dwData = IPC_PLAYFILE
cds\lpData = @ "file.mp3"
cds\cbData = SizeOf(character) * (SizeOf(cds\lpData) + 1)
SendMessage_(hwnd_winamp,#WM_COPYDATA,0,@cds)


it is not working. Does someone have a clue what to change to make it work?

thanks in advance!

Mike
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: Winamp Example

Post by kenmo »

I haven't looked through the whole code, but...

First:

Code: Select all

cds\dwData = #IPC_PLAYFILE
You still need the # before a constant name, when you use it.

Second:
Is the lpData field of COPYDATASTRUCT a string, or just a regular integer/pointer?

If it's a string, just use

Code: Select all

cds\lpData = "file.mp3"
If it's an integer, use something like

Code: Select all

Global filename.s = "file.mp3"
cds\lpData = @filename 
since you can't directly get the address (@) of a string explicitly written in your code.

Nice job bringing back a 10-year-old thread 8)
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: Winamp Example

Post by TomS »

First of all you should use an absolute path like "C:\myMusic\file.mp3"

But why don't you just use RunProgram()?

Something like "winamp.exe file.mp3" should load the file.
There's also a switch /enqueue or something like that to add the file to the playlist instead.
verleihnix
User
User
Posts: 13
Joined: Sun Dec 14, 2008 4:55 am
Location: Switzerland

Re: Winamp Example

Post by verleihnix »

Thanks for your support!

i tried to adjust the code like so (according the information given from kenmo):

Define cds.COPYDATASTRUCT
Global filename.s = "C:\Users\Mike\Downloads\winamp\song.mp3"
cds.COPYDATASTRUCT
cds\dwData = #IPC_PLAYFILE
cds\lpData = @filename
cds\cbData = SizeOf(character) * (SizeOf(cds\lpData) + 1)
SendMessage_(hwnd_winamp,#WM_COPYDATA,0,@cds)

still no success, the file ist not loading. So i followed TomS's advice and started the winamp with the queing command.
RunProgram(). The only negative thnig i can see is, i am writing a watch process for multiple winamps each 200ms its checking them and see if a file is playing. and if not load a new file. i think the call with the copydatastruct is much faster than an external runprogram(). So if someone has time to look into this we can close this thread forever (RIP) ;)

Geez i wish i would know more C language this would help in this situation.

greets Mike
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Winamp Example

Post by netmaestro »

cds\cbData = SizeOf(character) * (SizeOf(cds\lpData) + 1)
This looks wrong. The cbData member should contain the length of the string. Here you have SizeOf(Character), which is 1 in non-unicode mode, times SizeOf(cds\lpData), which is 4, plus 1. All this evaluates to 5 and you need StringByteLength(filename)+SizeOf(Character), which here would be 40.

See if that helps and good luck!
BERESHEIT
verleihnix
User
User
Posts: 13
Joined: Sun Dec 14, 2008 4:55 am
Location: Switzerland

Re: Winamp Example

Post by verleihnix »

Hello all

thanks to all of you this thread can be archived for future reference!

the mistery is solved!

the following lines did the trick:

Define cds.COPYDATASTRUCT
Global filename.s = "C:\Users\Mike\Downloads\winamp\song.mp3"
cds.COPYDATASTRUCT
cds\dwData = #IPC_PLAYFILE
cds\lpData = @filename
cds\cbData = StringByteLength(filename)+SizeOf(Character)
SendMessage_(hwnd_winamp,#WM_COPYDATA,0,@cds)

Tested and working.

Greetings Mike
Post Reply