i input the number from a text box and it gose into the list and then plays the songs from the list
Printable View
i input the number from a text box and it gose into the list and then plays the songs from the list
I don't quite understand what all this button mess is supposed to do. It seems to me there ar about 17 buttons with some sort of mutual exclusion. For this we got the OptionButton, also known as radio button. Set their Style property to graphical and they look exactly like a CommandButton. Put some of them in a frame and they work automatically just like that, that only one of them is pressed at a time and if you click on one of them all the others are released.
Concerning the playing: Our help would be more precise and would be less confusing for you if you could give us some facts:
Give the folder name where the song files are.
Give one or two examples of the existing file names.
Are the filenames the song titles or do you want to display a title text which is not the very same as the file name?
With this information I could direct you to some method of associating all together with the 4 digit number.
the folder name is music
two of the files
Symphony_No_3.wma
Ome Step Beyond.wma
the file names are going to be the same as displayed
and i would like it to play from a list box when a 4 digit number is enterd into it
Right. Let's do a simple approach.
We take a ListBox named lstSoundFiles and fill it up at Form_Load()
Note how I have simply put the 4 digit number in front of the actual filenameCode:Private Sub Form_Load()
lstSoundFiles.AddItem "1234: Symphony_No_3"
lstSoundFiles.AddItem "1235: One Step Beyond"
'... more to come
End Sub
We take an input field TextBox named txtSel, where we will enter the number.
We will further take a button named btnPlay to play the selection.
This is the Click routine of the play button
How it works: It scans through all items of the ListBox for the 4 digits you entered in the input field. If they were found, the filename is separated from this ListBox entry, combined with the folder name and the ending and then used in the PlaySound statement to play it.Code:Private Sub btnPlay_Click()
Dim n$, f$, i%
n$ = txtSel.Text
'a test could be put here to verify we have 4 digits
For i = 0 To lstSoundFiles.ListCount - 1
If Left$(lstSoundFiles.List(i), 4) = n$ Then
'cut off the preceding number
f$ = Mid$(lstSoundFiles.List(i), 7)
txtMessage.Text = "Playing " + f$
PlaySound "C:\music" & f$ & ".wma", 0, SND_MEMORY
Exit Sub
End If
Next
'if we come here we have not found the number in the list
txtMessage.Text = "Not found: " & n$
End Sub
I have attached the small sample as a working project for you to examine.
BTW. I'm not sure if PlaySound can handle .wma files. I can't verify since I have no .wma music on my computer here. I'm only sure PlaySound can play a .wav file.
Oops, sorry, there's a small mistake in the PlaySound line. I missed the "\" between Path and filename.
This is what it should be:
Code:PlaySound "C:\music\" & f$ & ".wma", 0, SND_MEMORY
tis is ok but i want to start with no song in the list and then when they input a 4 digit number it adds the song that relates to that number then plays it from the list i dont want to use a 4 digit number to select a song from then list
have a look at the word document that i posterd earlia to find out how i have got it
Well, I wanted to show you how an association and selection mechanism could be implemented, which takes a 4 digit number and resolves it into a filename to play.
Other techniques are possible too, but this here seemed quite comprehensive to me.
(Although I wouldn't dare show this to CPUWizard ;) )
Just imagine that you make this ListBox invisible so it doesn't show up on your screen. Nevertheless you can use it to determine the filename from a 4 digit number, provided that you fill this ListBox at Form_Load() with all your song filenames.
Now you have to think a little for yourself:
Instead of using the PlaySound statement at this position, you can use something like this:
This adds the determined filename to a ListBox called lstPlayList.Code:lstPlayList.AddItem f$
Now you only have to write a little loop which plays the files in lstPlayList one after the other.
If you need further help for this, we surely can make more proposals as how to accomplish this.
i will do it how you did it in the earlya reply.
just one more thing tho how do i get it to loop
and i actully cant get that one that u posted to play sound
Go back to my sample, and see how I set the folder and file name
Actually, I think PlaySound cannot handle .wma files. It only plays .wav
We have to find an API call to play .wma music. :)
i have converted one of my audio files to wav but it still wont play sound
Before playing the file, check if the path is assembled correctly. You could dos so by checking the filesize like this:
If you have not assembled the filename correctly the program shows an error 'File not found'.Code:' first build the filename, where f$ is the name from the list
p$ = "C:\music\" & f$ & ".wav"
' now check if the file exists. l must be dimmed a Long
l = FileLen(p$)
' then try to play it
PlaySound p$, 0, SND_MEMORY
If the file exists in the place where you specified it, the PlaySound must play it.
Please do as described to find out if your filename assembly is correct.
well the sample that u posted i have adapted that to how i want it and it displays the name of the track that has been selected but it just wont play.
i have check the path for the audio but it just wont play.
by any chance do i need a media player control or not?
if i dont will it be easyer if i had one?