How do you add music to an app and in what form. .mp3? .wav?
Printable View
How do you add music to an app and in what form. .mp3? .wav?
put this in a module
and add this to a command button or whateverCode:Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
d is just there as a blank thing.. because I dont know what the last to arguments are for :(Code:Private Sub Command1_Click()
Dim d As Long
Call PlaySound("c:\windows\desktop\dennis3\Genflit0.wav", d, d)
DoEvents
End Sub
for some reason it kind of locks up.. it freezes the program you have to keep hitting the stop button(in the Vb IDE)
I am not sure why though. :(
'Play A sound
'Paste this code into a bas module
'
'API Function to play the sound
'
Declare Function sndPlaySound Lib "winmm" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
'
' play synchronously (default)
Public Const SND_SYNC = &H0
' play asynchronously
Public Const SND_ASYNC = &H1
' loop the sound until next
Public Const SND_LOOP = &H8
'=====================================================
'Paste this code into the main
'from your main program (button or load or whatever):
'call the function using your wave file & location..replace "A:\whoosh.wav"
'
Call sndPlaySound(ByVal "a:\whoosh.wav", SND_ASYNC)
Use the mciSendString to play a MIDI file.
Code for module.
Put this code in a CommandButtonCode:Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Put this code in another CommandButton. You must press this button to stop playing the music.Code:Private Sub Command1_Click()
' Open's the MIDI
mciSendString "open C:\Mptheme.mid type sequencer alias background", 0, 0, 0
' Play's the MIDI
mciSendString "play background", 0, 0, 0
End Sub
Code:Private Sub cmdStop_Click()
' Closes the MIDI
mciSendString "close background", 0, 0, 0
End Sub
I put this in module1:
Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
I put this in form1:
Private Sub Command1_Click()
' Open's the MIDI
mciSendString "open C:\Program Files\Pest\Hall.mid type sequencer alias background", 0, 0, 0
' Play's the MIDI
mciSendString "play background", 0, 0, 0
End Sub
Private Sub Command2_Click()
' Closes the MIDI
mciSendString "close background", 0, 0, 0
End Sub
My forms and buttons are set, "Winmm.dll" is in my system files, the file "hall.mid" is where it should be and my midi is not muted on my sound card's mixer.
What the hell am I doing wrong?
[b]Mikeycorn. That is EXCATLY the same thing that Megatron posted!!! You just changed the Filename!
Before you post, read the replies that were mentioned earlier! Especially if it's almost 1 month old!!
mikeycorn
Re: What the hell am I doing wrong...
Code:'don't know about Meg's code
'but my code works fine
'
'API Function to play the sound
'
Public Declare Function sndPlaySound Lib "winmm" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
'
' play synchronously (default)
Public Const SND_SYNC = &H0
' play asynchronously
Public Const SND_ASYNC = &H1
' loop the sound until next
Public Const SND_LOOP = &H8
Private Sub Command1_Click()
Call sndPlaySound(ByVal "c:\yourfolder\yourfile.mid", SND_ASYNC)
End Sub
Private Sub Command2_Click()
Call sndPlaySound(0,0)
End Sub
Hey Zej,
I wasn't replying to the first post, I had cut and pasted Megatron's code and it wasn't working for me, okay? It might have been redundant to post the code again with nothing changed but the file name, but I was perplexed as to why it wouldn't work for me.