PDA

View Full Version : Winamp's File Loading Syntax Question


X5darkmage
26th March 2002, 01:15
Hi, I'm looking to code up a small program in Visual Basic 6 that will, upon a command button click, will load a predetermined (hard-coded :D ) playlist file (for use with internet radio stations) within the program directory. I think I've figured out how most of the code will look, but I still need to know how to access Winamp from an external program, and make it load a file. I'm not looking to code a plug-in, as I want this to be as simple as can be, and to be an external program, in case I have to decompile it and make changes quickly.

I looked at the sample VB code for adding files to Winamp's internal playlist (found it in the NSDN Code Vault), but:

1) I want my saved playlist file to open immediately, and not be added to the Winamp internal playlist.

2) All that code was too confusing for a novice VB coder (less than 1 year of experience) like myself to understand, so as to tailor it to my needs.

Is there a simple VB6 command, or set of commands, that I can execute, that will call up Winamp, and have it load a file on demand? Any and all help would be greatly appreciated. Thank you!

-Mage

Gourou
26th March 2002, 09:34
1) I want my saved playlist file to open immediately, and not be added to the Winamp internal playlist.
nope, nope, nope, if you want winamp to play something, it has to be in it's internal playlist, there is no way to just play something and not change the playlist. However, if you load a playlist, then hit play, it loads right away, so it will play right away

To load up one on the fly, just execute winamp again with the selected playlist command. e.g.
" c:\program files\winamp\winamp.exe c:\pls.pls "
even if winamp is running, it will load your playlist without running another winamp

if you dont know how to do that with vb, the command is Shell() remember to use quotes or vb will say some gibberish about it not being valid

X5darkmage
26th March 2002, 16:57
I'm pretty sure I can make that work for myself (this IS a personal program, anyway), with having the playlist load itself, then manually pressing play... although, it would be nice if I could send a command to Winamp to Play through a command line modifier or something, which would Play the playlist immediately after loading. :)

Originally posted by Gourou if you dont know how to do that with vb, the command is Shell() remember to use quotes or vb will say some gibberish about it not being valid

How exactly do I use the Shell command? Like, what would the syntax be? Like I said, I'm a novice coder, and relatively new to the VB system. I don't quite know all these really cool advanced functions, like Shell. :D Thanks again!

-Mage

P.S. If I figure this out, and can get my launcher to work, I could probably rig it up to load filenames from whatever is in the program directory, or from a user-specified text file... now wouldn't that be cool! For reference, I'm coding this first personal launcher to work with the Digitally Imported (http://www.digitallyimported.com/) and Bluemars (http://www.bluemars.org/) radio stations. Great net radio. :D

Gourou
27th March 2002, 23:39
ok, you can send winamp a play command :)
it's called API calls, but I get the feeling that is a bit over your head :D
Shell is a function, for starters, so dump it something like this
' ' '
Dim nullV As Long
nullV = Shell("C:\program files\winamp\winamp.exe C:\myplaylist.pls")
' ' '

This will play the playlist immediately, you dont have to manually press play, it's the same thing as double clicking a file and it play in winamp
I could probably rig it up to load filenames from whatever is in the program directory, or from a user-specified text file...
If you want to load from file, do something like
' ' '
Open App.Path & "\mylist.txt" For Input As #1
Dim ToLoad
Line Input #1, ToLoad
Dim nullV As Long
nullV = Shell("C:\program files\winamp\winamp.exe " & ToLoad)
Close #1
'''
or an enqueue command :)
'''
Open App.Path & "\mylist.txt" For Input As #1
Dim ToLoad
Dim nullV As Long
Do Until EOF(1)
Line Input #1, ToLoad
nullV = Shell("C:\program files\winamp\winamp.exe /add " & ToLoad)
Loop
Close #1
' ' '
if you want that nice play command, here it is :)
' ' '
'---put this in a module...---
' ' '
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public hwndWinamp as long

' ' '
'---then this in your Form_Load---
' ' '
hwndWinamp = FindWindow("Winamp v1.x",vbNullString)
SendMessage(hwndWinamp, &H400, 0, 100)
' ' '
that's it :)
that's what you need to press play, of course, once you set that up, doing other functions are easy, like pressing stop would now take a single SendMessage command, and so on

X5darkmage
28th March 2002, 01:42
Gourou, I bow down to you now. Thank you for all this help! Tomorrow is coding day, and later test day (I'll have to code it away from home, since I don't have a copy of VB6 for myself, and then bring it home for final testing). I'll let you know how it turns out, but I think it'll function perfectly if I put my mad copy-and-paste skills to work. :D

No matter what, though, I still bow to you, Gourou. :D

-Mage

X5darkmage
28th March 2002, 20:57
Just a follow-up:

It worked! YES! The actual code for each command button resembled something like this:

Shell ("C:\Program Files\Winamp\Winamp.exe " & App.Path & "\trance128k.pls")

A friend of mine (also a novice VB6 coder) found some example code from a website, and showed it to me. Didn't see why it needed to be sent to a variable anyway, so I wrote it up with just the Shell function on a line, and hey, it works. Fun fun fun. :D Only noticeable bug appears when you try to run the program from a directory with spaces or something. Didn't take the time to find out what was wrong - put it into a simple directory on my C: drive's root, and that cleared it all up.

Thanks again for all your help, Gourou. The next part is to make it compatible with user-specified playlists, and other stuff, but that'll be for after Spring Break. :)

-Mage

Gourou
28th March 2002, 23:04
yeah, it's normally a function, sending to the variable is used to keep it from erroring when the pathnames are invalid :)
I dunno why it doesnt work on a path with spaces, I dont have that prob at all :weird: oh well
email me at SuperSpyGouRou@hotmail.com if ya want some more help, I'm on 4 different messengers and I'm usually here if ya need more code, and good luck to you.
P.S. I have a parser for pls and m3u playlists :)
I think you need something like that.. :D
P.P.S. If ya want another idea, just load all the .pls files and .m3u files in a specified directory, that wouldnt take much more code, either parse each one, or have it send the entire playlist, you could also let the user choose :)

X5darkmage
29th March 2002, 01:42
I've got big plans for my little radio launcher. Don't think I'm done with this project yet. ;)

Yeah, I don't see why it wouldn't handle spaces in the path at all. I'll play with it some more, and see what makes it screw up. All part of making a program, isn't it? :D

Just wish I had a copy of VB6 for myself... maybe the school will be nice, and let me "borrow" one of their installers... hehehe.

-Mage

Gourou
29th March 2002, 04:00
I could 'lend' you mine if you have a fast connection at home, I dont have the fastest upload, but 56gay is too slow even with my upload, as I said, email me and we'll work something out, and here is something for you..:

' ' '
Dim PlayLists(255) As String
Dim Count As Integer
Dim FilePath As String
'
Open App.Path & "\Init.ini" For Input As #1
Line Input #1, FilePath
Close #1
'
PlayLists(Count) = Dir(FilePath & "\*.pls", vbNormal)
Count = Count + 1
Do
On Error GoTo ExitLoop
PlayLists(Count) = Dir
Count = Count + 1
Loop
ExitLoop:
'
PlayLists(Count) = Dir(FilePath & "\*.m3u", vbNormal)
Count = Count + 1
Do
On Error GoTo ExitLoop
PlayLists(Count) = Dir
Count = Count + 1
Loop
ExitLoop:
' ' '

As you can see, the file names are stored in an array, this is so we dont have the incredibly crappy slow down if we were to use a list box, this also makes it rather easy to parse the names back out. Your Init.ini would store something like "C:\Lists" without the quotes, this would make it so you can change all the paths without recompiling the program, but that's up to you. I would indent properly, but the forums remove the spaces :p

X5darkmage
29th March 2002, 20:48
Code-at-work - such a beautiful thing. :D

I emailed you - you should have it by now... go check. :)

-Mage

Gourou
30th March 2002, 18:25
fun fun fun

if anyone else cant figure out how to do something, as long as it's talking about something having to do with winamp, I'll help

X5darkmage
31st March 2002, 13:07
Yeah, if you need some help, talk to Gourou here. He knows what he's talking about. I speak from experience. :D

-Mage

gfx_sikander
28th April 2004, 17:26
can anyone tell me how to send this sendMessage calls in vc++ ??