|
-
May 30th, 2002, 11:48 AM
#1
Thread Starter
Junior Member
Play Sound
How Do You Get Your Project To Play A Sound.... For Instance Lets Say I Did This
Code:
Private Sub Form_MouseUp(Button As Integer, Shift As Integer)
'I Want The Sound To Play Here
End Sub
thanks in advanced
-
May 30th, 2002, 12:10 PM
#2
Fanatic Member
well
theres always the multimedia control (add-ins) or u can use directX, which i have no idea how to.
Don't pay attention to this signature, it's contradictory.
-
May 30th, 2002, 01:15 PM
#3
Frenzied Member
Try something like this:
VB Code:
Option Explicit
'API Declarations
#If Win32 Then '32-Bit windows
Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long 'The API that lets sound be played
#Else 'Other Windows
Public Declare Function sndPlaySound Lib "MMSYSTEM.DLL" _
(ByVal lpszSoundName As Any, ByVal wFlags As Integer) As Integer 'The API that lets sound be played
#End If
'API Constants Used for flags in Play Sound function
Public Enum SoundFlags
SND_LOOP = &H8 ' Loop the sound until next sndPlaySound
SND_ALIAS = &H10000 ' Name is a WIN.INI [sounds] entry
SND_ALIAS_ID = &H110000 ' Name is a WIN.INI [sounds] entry identifier
SND_ALIAS_START = 0 ' Must be > 4096 to keep strings in same section of resource file
SND_APPLICATION = &H80 ' Look for application specific association
SND_ASYNC = &H1 ' Play asynchronously
SND_FILENAME = &H20000 ' Name is a file name
SND_MEMORY = &H4 ' lpszSoundName points to a memory file
SND_NODEFAULT = &H2 ' Silence not default, if sound not found
SND_NOSTOP = &H10 ' Don't stop any currently playing sound
SND_NOWAIT = &H2000 ' Don't wait if the driver is busy
SND_PURGE = &H40 ' Purge non-static events for task
SND_RESERVED = &HFF000000 ' In particular these flags are reserved
SND_RESOURCE = &H40004 ' Name is a resource name or atom
SND_SYNC = &H0 ' Play synchronously (default)
SND_TYPE_MASK = &H170007
SND_VALID = &H1F ' Valid flags / ;Internal /
SND_VALIDFLAGS = &H17201F ' Set of valid flag bits. Anything outside
End Enum
Private Sub PlaySound(ByVal FileName As String, _
Optional Flags As SoundFlags = SND_FILENAME Or SND_NOSTOP)
On Error Resume Next 'Goto next line on an error
'If the filename is not "" then play the sound
If FileName <> "" Then Call sndPlaySound(FileName, Flags)
End Sub
-
Jun 1st, 2002, 08:05 AM
#4
Lively Member
I got it to play sound... but it stops everything in the program until it is done playing... What fixes that?
-
Jun 1st, 2002, 09:04 AM
#5
Frenzied Member
I haven't done this for years and I believe I did it a different way but if you look at the flags setting it to asynchronus should work...
Can't say for sure I always use DirectSound
Sanity is a full time job
Puh das war harter Stoff!
-
Jun 1st, 2002, 09:31 AM
#6
Lively Member
I think I've tried that, but I'm not sure I've done it right.
PlaySound ("filename"), (SND_SYNC)
Is that right? If so, it still freezes while it plays a sound.
-
Jun 1st, 2002, 10:04 AM
#7
Good Ol' Platypus
Use the SND_ASYNC (Asynchronous) flag to allow execution while the sound plays.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jun 1st, 2002, 10:08 AM
#8
Lively Member
Hmm... it works now.. even though I already tried it and it didnt Oh well...
-
Jun 1st, 2002, 12:05 PM
#9
Frenzied Member
Yeah sorry about that, the default flags should have had "Or SND_ASYNC" there too.
-
Jun 2nd, 2002, 03:09 AM
#10
-
Jun 2nd, 2002, 06:33 AM
#11
Frenzied Member
I couldn't be bothered to put my speakers on to test it, but do you need to specify the absolute path, not just "sound_1.wav"? Something like App.Path & "\Sound_1.wav". I've never use the multimedia control, so I'm not sure.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|