|
-
Nov 23rd, 2000, 01:10 PM
#1
Thread Starter
New Member
Originally (before I found out about API), the only way that I could play sound files was to use the Multimedia Control. My code basically consisted of about four to five lines of code, just to play a simple sound file.
I'm very new to API, and I was just wondering if there was a simple way of playing sound files using an API call.
Thanks to anyone who can help.
-
Nov 23rd, 2000, 01:17 PM
#2
Use the PlaySound api function.
Code:
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule _
As Long, ByVal dwFlags As Long) As Long
Private Sub Command1_Click()
PlaySound "C:\MyFile.wav", 0&, &H1
End Sub
-
Nov 25th, 2000, 10:43 AM
#3
After you've 'stopped' your MIDI, you should use the following statement to close it.
Code:
mciSendString "close myfile", 0, 0, 0
-
Nov 26th, 2000, 03:53 AM
#4
Hyperactive Member
DX?
And what about DirectX?
or is it slower
WP
-
Nov 26th, 2000, 06:40 AM
#5
Frenzied Member
DirectX (DirectSound) is more complex but not slower than API.
-
Nov 26th, 2000, 12:08 PM
#6
You should only use DirectSound if you are planning to use other DirectX function in your App. Otherwise, you'll have to include the Type Library all for a couple sounds.
-
Nov 26th, 2000, 11:16 PM
#7
Hyperactive Member
SndPlaySound API Function
The easiset API for playing conventional sounds is:
code:
option explicit
Private Declare Function sndPlaySound _
Lib "winmm.dll" Alias "sndPlaySoundA" ( _
ByVal lpszSoundName As String, _
ByVal uFlags As Long _
) As Long
Private Sub Command1_Click()
sndPlaySound("C:\windows\media\start.wav", &H1)
End Sub
Hope it Works
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Dec 5th, 2000, 02:43 AM
#8
New Member
Stopping a sound
How do I stop a looping sound file from playing without playing another sound file?
I've looked up the VB API at http://www.vbapi.com/ref/p/playsound.html and the example:
retval = PlaySound("", 0, SND_PURGE OR SND_NODEFAULT) doesn't work on my program.
NOTE: I also even set the values of SND_PURGE and SND_NODEFAULT to what they are meant to be.
-
Dec 5th, 2000, 08:51 AM
#9
To stop a sound:
Code:
Private Sub Command2_Click()
PlaySound "C:\WavFile.wav", 0&, &H4
End Sub
-
Dec 18th, 2000, 08:36 PM
#10
Lively Member
Is it Possible to play MP3's using DirectX or Direct Sound?
All the above API's will play .wav or .midi. Those API's will not play MP3. Is it Possible to play MP3 files using DirectX or DirectSound. How will be the Quality of the Sound. I'm having DirectX 7a. If it is possible to play, please send me the coding.
-
Dec 20th, 2000, 03:30 AM
#11
playing sounds
Originally posted by Marble
Originally (before I found out about API), the only way that I could play sound files was to use the Multimedia Control. My code basically consisted of about four to five lines of code, just to play a simple sound file.
I'm very new to API, and I was just wondering if there was a simple way of playing sound files using an API call.
Thanks to anyone who can help.
I am trying create a CD menu which plays sounds, i can get the form to play the sound using a API call but the problem i have is that the sound plays without the form being displayed. the form only appears after the sound stops.
i think i need to create the EXE as a multi threeded application but i dont know how.
-
Dec 20th, 2000, 01:22 PM
#12
Lively Member
To play an mp3 file instead use this code
Code:
Public Function PlayMP3(Filename As String)
Dim dwreturn As Long
Dim ret As String * 128
Dim tmp As String * 255
Dim lenShort As Long
Dim ShortPathAndFie As String
'send a filename to the function
If Dir(FileName) = "" Then
msgbox "Error with input file"
Exit Function
End If
lenShort = GetShortPathName(FileName, tmp, 255)
ShortPathAndFie = Left$(tmp, lenShort)
glo_hWnd = hwnd
cmdToDo = "open " & ShortPathAndFie & " type MPEGVideo Alias mpeg"
dwreturn = mciSendString(cmdToDo, 0&, 0&, 0&)
If dwreturn <> 0 Then 'not success
mciGetErrorString dwreturn, ret, 128
MsgBox ret, vbCritical
Exit Function
End If
'then to play just send this
dwreturn = mciSendString("play mpeg", 0&, 0&, 0&)
If dwreturn <> 0 Then
mciGetErrorString dwreturn, ret, 128
MsgBox ret, vbCritical
Exit Function
End If
End Sub
This will also play wavs...
-
Dec 21st, 2000, 03:58 PM
#13
Re: SndPlaySound API Function
Originally posted by Wak
The easiset API for playing conventional sounds is:
code:
option explicit
Private Declare Function sndPlaySound _
Lib "winmm.dll" Alias "sndPlaySoundA" ( _
ByVal lpszSoundName As String, _
ByVal uFlags As Long _
) As Long
Private Sub Command1_Click()
sndPlaySound("C:\windows\media\start.wav", &H1)
End Sub
Hope it Works
sndPlaySound has been superseded by PlaySound
-
Dec 22nd, 2000, 04:54 PM
#14
Thread Starter
New Member
Thanks for your help everyone! I didn't expect this many replies
-
Dec 23rd, 2000, 05:48 AM
#15
Hyperactive Member
MEGATRON....
[quote]
sndPlaySound has been superseded by PlaySound
[/qoute]
I realize what your saying and all, but the guy just wants to play a sound. What really confused me when I started
out, is when you have a really simple question, and people
swamp you with all this crap, which makes you even more confused. He said he's just new to API, so why give him
an unecessarily hard API function when the easy one will do
the trick. I mean, he only wants to play a sound. Probably for a mouse event or something. NO OFFENCES.
Thanx 
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Dec 23rd, 2000, 01:35 PM
#16
How is PlaySound "an unecessarily hard API function"? They're practically the same, except PlaySound allows you to play through a module. If you don't intend to use this argument this simply omit it.
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
|