^
^
^
^
Printable View
^
^
^
^
If you want the simplest way to do it, use the 'Playwave' API call, but remember that it is very limited.
Hope this helps!VB Code:
Private Declare Function Playwave Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long Private Sub Command1_Click() Call Playwave(App.Path & "\sound.wav", 1) End Sub
Where did you find that? The name doesn't matter when you are calling a .dll, but I've never seen PlayWave. Are you trying to track how many people copy your post? :)
VB 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 "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_ASYNC Or SND_LOOP Else Command1.Caption = "Play" PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_MEMORY End If flag = Not flag End Sub Private Sub Form_Load() 'KPD-Team 2000 'URL: [url]http://www.allapi.net/[/url] 'E-Mail: [email][email protected][/email] Command1.Caption = "Play" End Sub
You can call an API by whatever name you want to as long as you alias it in the declaration. i tought you knew that dglienna. ;)
When I try to put that declare function Playsounds thing in the form code, it said I can have only comments after end function. When i put it in a module, when I try to use the function, it can't find it. I'm so confused. Also, I'm trying to use nBass to have my program play mp3 and wma files. I dunno how to get it to play my music. Plz help
Post your code. If you paste my code, and the filenames sync, then it will run without problems.
Ok, now the sound works fine and all. But when the sound plays, I can't move my cursor...
Post your code. I have the code in a button. If you have it in form load, that may throw things off. We need to see what you have tried.
You mean the mouse or the cursor like when a textbox has the focus?
I'll show you.
I just added two option buttons, and while the wav was looping, was able to click on both of them. I could also tab between the three controls while it was playing. There must be something in your code.
No way am I gonna use option buttons or command buttons or etc. Yeah, I know you could click on them while the wav is playing but I wanna make this one work...
Here's part of my code:
Code:Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyDown) <> 0 Then
If Image2.top <> 480 Then
Image2.top = Image2.top + 48
Else
Image2.top = Image2.top - 96
End If
PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", 0, SND_SYNC
ElseIf GetAsyncKeyState(vbKeyUp) <> 0 Then
If Image2.top <> 384 Then
Image2.top = Image2.top - 48
Else
Image2.top = Image2.top + 96
End If
PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", 0, SND_SYNC
End If
If GetAsyncKeyState(vbKeyReturn) <> 0 And Image2.top = 480 Then
RetValue = ChangeRes(1280, 800, 32)
End
ElseIf GetAsyncKeyState(vbKeyReturn) <> 0 And Image2.top = 432 Then
LoadScreen.Show
Unload TitleScreen
End If
End Sub
How often is the timer firing?
The timer may be firing too fast causing the thread to peg out the CPU until its done.
You use the SND_SYNC flag in your PlaySound call which means the function doesn't return until the wave file has finished playing, so no other code you use can run. Use the SND_ASYNC flag instead.VB Code:
Private Const SND_ASYNC As Long = &H1
Good spot Joacim. :thumb: We all missed that one. :blush:
Still doesn't work >.>
The interval is 100Quote:
Originally Posted by dglienna
That is 10 times per second. Change it to 1000 (one second) to see if that fixes things. The timer can't reference less than 10ms, and there is no way for the user to click that fast. If that works, you could try 750, or 500.
It also takes time to move the image. The timer fires again and again, but can't do anything in the time you've given it.
In the project you posted you don't play any sound files. Did you change the call to PlaySound to use the SND_ASYNC flag instead of SND_SYNC? I don't think the Interval of the Timer is especially relevant to this issue.
[QUOTE=Joacim Andersson]Did you change the call to PlaySound to use the SND_ASYNC flag instead of SND_SYNC? QUOTE]
Yes I did...
Well, not in the project you posted. Can you post the code where you call the PlaySound API function.