[RESOLVED] Having trouble with Listbox
Hey guys im working on a small mp3 streaming client and im having trouble getting a listbox to display the .mp3 files in a specific directory on my server. I wanna have this listbox display all the different mp3 tracks in my directory so when the user double clicks the track name in the listbox it will redirect the mediaplayers url to start the stream of the song. So can anyone help me with this thanks in advanced :)
Re: Having trouble with Listbox
vb Code:
mypath = "c:\mp3s\" 'change to suit
fname = dir(mypath & "*.mp3")
do while len(fname) > 0
list1.additem fname
fname = dir
loop
Re: Having trouble with Listbox
what do i dim mypath,fnam,and dir as?
Re: Having trouble with Listbox
What kind of server is it?
Re: Having trouble with Listbox
Quote:
Originally Posted by
FireXtol
What kind of server is it?
i have all the .mp3 files hosted on a website. How can i get them to showup in the listvbox?
Re: Having trouble with Listbox
the server is just a linux VPS.
Re: Having trouble with Listbox
So you're probably using Apache, basically some HTTP server? Is the directory they're in public?
You'll need to use something like Inet or Winsock to request the directory contents, then parse the response.
Re: Having trouble with Listbox
Quote:
Originally Posted by
FireXtol
So you're probably using Apache, basically some HTTP server? Is the directory they're in public?
You'll need to use something like Inet or Winsock to request the directory contents, then parse the response.
yes it is a simple http apache server and there in a public directory i dont have the .htaccess file restricting anything from viewing it.
Re: Having trouble with Listbox
So how far along are you? Do you need help with the downloading of the directory list from the server, and/or parsing the response?
Re: Having trouble with Listbox
Quote:
Originally Posted by
FireXtol
So how far along are you? Do you need help with the downloading of the directory list from the server, and/or parsing the response?
yes im still trying to figure out that but ive never done that before so i would have no clue were to start from :/
Re: Having trouble with Listbox
I'd suggest Inet. Goto Components | Controls and check: Microsoft Internet Transfer Control
Add the control to a form and add some code:
vb Code:
Dim strDirs As String
strDirs = Inet1.OpenURL(YOUR_URL_HERE)
Most likely your server will return a list of links. You can use StrFindBetween, for instance, see the link in my sig under Strings. You'll want to find: "<a href=""" to """>", then perform an Instr on the string between those two strings. In the Instr determine if there's a forward slash "/", and if so treat that as a directory, and not a file. If it's a file(and not a directory), then instr for the ".MP3" extension, and if so add it to the list.
Now, add a List1, and try this:
vb Code:
Dim strDirs As String, strResult As String
Dim X As Long, Y As Long
strDirs = Inet1.OpenURL("some_url_here")
X = InStr(strDirs, "<a href=""")
Do While X > 0
X = X + Len("<a href=""")
Y = InStr(X, strDirs, """>")
If X And Y Then
strResult = LCase$(Mid$(strDirs, X, Y - X))
If InStr(strResult, "/") Then
'directory
ElseIf InStr(strResult, ".mp3") Then
'mp3 file
List1.AddItem Mid$(strDirs, X, Y - X) 'names are case sensitive, so re-fetch this
Else
'other file
End If
Else
Exit Do 'we're out of string, there are no matches
End If
X = InStr(Y, strDirs, "<a href=""")
Loop
Re: Having trouble with Listbox
its not returning any values into the listbox :(
Re: Having trouble with Listbox
oh i got it to work thank you for all your help :)
Re: Having trouble with Listbox
Quote:
Originally Posted by
GGGuardian
oh i got it to work thank you for all your help :)
You're welcome. :)