hi i am trying to creat a jukebox where you enter the number of the track that you want and it will put it into a list box and then play i have managed to get the cod working for the track number to be placed in the list box but i am unable to get the audio to play from the list box.
if anyone could post how to do it and the code that i will need i will be realy plesed
Option Explicit
Public SoundFile() As String
Sub LoadSounds()
ReDim SoundFile(0) As String
SoundFile(0) = "C:\WINDOWS\MEDIA\TADA.WAV"
End Sub
and then this in a form:
Code:
Option Explicit
Private Const SND_APPLICATION = &H80 ' look for application specific association
Private Const SND_ALIAS = &H10000 ' name is a WIN.INI [sounds] entry
Private Const SND_ALIAS_ID = &H110000 ' name is a WIN.INI [sounds] entry identifier
Private Const SND_ASYNC = &H1 ' play asynchronously
Private Const SND_FILENAME = &H20000 ' name is a file name
Private Const SND_LOOP = &H8 ' loop the sound until next sndPlaySound
Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file
Private Const SND_NODEFAULT = &H2 ' silence not default, if sound not found
Private Const SND_NOSTOP = &H10 ' don't stop any currently playing sound
Private Const SND_NOWAIT = &H2000 ' don't wait if the driver is busy
Private Const SND_PURGE = &H40 ' purge non-static events for task
Private Const SND_RESOURCE = &H40004 ' name is a resource name or atom
Private Const SND_SYNC = &H0 ' play synchronously (default)
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Dim flag As Boolean
Private Sub Command1_Click()
If Not flag Then
Command1.Caption = "Stop"
PlaySound SoundFile(0), ByVal 0&, SND_ASYNC Or SND_LOOP
Else
Command1.Caption = "Play"
PlaySound SoundFile(0), ByVal 0&, SND_MEMORY
End If
flag = Not flag
End Sub
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Call LoadSounds
Command1.Caption = "Play"
End Sub
thanks for the reply.
how would i be able to play audio from me entering a 4 digit number into a listbox
You need to associate the 4 digit number to the filename which contains the audio you wish to play. Use the play sound function outlined in the code posted earlier to have it play the sound you want.
i have tryed what was sergesterd but it will only let me change the numbers between the brackets to a number between 0 and 9 plz explain how to do it if i am doing somthing wrong
Private Sub Form_Load()
Dim song As String, num As Integer
song = InputBox("Enter the song to play:")
num = Val(song)
' do some error checking here
Call LoadSounds(song)
End Sub
Sub LoadSounds(ByVal sn As Integer)
Dim DrvFolder As String ' "C:\TEMP\"
Dim SngExt As String ' "wav"
Dim SngToPlay As String
SngToPlay = DrvFolder & Format(sn, "0000") & ".WAV"
SoundFile(0) = SngToPlay
End Sub
Private Sub Command1_Click()
If Not flag Then
Command1.Caption = "Stop"
PlaySound SoundFile(0), ByVal 0&, SND_ASYNC Or SND_LOOP
Else
Command1.Caption = "Play"
PlaySound SoundFile(0), ByVal 0&, SND_MEMORY
End If
flag = Not flag
End Sub
Simply replace the SoundFile(0) portion above with the filename you want to play or assign SoundFile(0)=The filename you want to play.
The load sounds portion in the code block is not needed but you do have to specify a valid filename for the playsound function.
Since you are using 4 digit track numbers in your list then either your filenames have to match those four digit numbers or you have to have another list or array set up to match the track number to the filename.
Let's say your filenames are the same 4 digits that are in the list and then have a wav extension and they exist in c:\MyMusic
In your list1 doubleclick event you could have something like the following assuming you used the full code block posted earlier.
Since David now delivered an easy to implement playing scheme, you only have to manage the file selection, as DataMiser hinted.
To me this seems to be the most important consideration: how is the file naming convention?
You might want to associate three different informations with each other:
a) Title of the song how it is displayed for selection
b) 4 digit number associated with it
c) actual name of the file to play
I rather wouldn't name my songs "0001.mp3", "1234.mp3" because you might loose overview.
Also I presume the files you want to put in have already comprehensive names.
E.g.: you need sort of a table which associates the informations:
0001, Help, Help-Beatles.mp3
0002, Paint it black, PaintItBlack-Stones.mp3
0003, Next Song's Title, NextSongsFileName.mp3
...
I would approach like that:
Write text file (with Editor) to contain such a list as shown above which links numbers to the display titles to the filenames.
At Form_Load() you read this file into an array or a collection or a ListBox or other element of your choice.
Then you have all the mechanisms you need to make your project work like shown in your planning.
i am still having trouble to get the audio to work as i cant assign an audio to a 4 digit number to each track and get that to go into a play list and then play from the play list it is so annoying that i have had loads of responses but i still cant get it to work
could some one plz explain how i would do this as it is driving me crazy
Private Sub cmd_log_off_Click()
Shell ("shutdown -l")
End Sub
Private Sub cmd_shut_down_Click()
Shell ("shutdown -s")
End Sub
Private Sub cmd_submit_Click()
List1.AddItem txt_number
End Sub
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.