PDA

Click to See Complete Forum and Search --> : Playing sound


drewski
Dec 26th, 2000, 06:15 PM
Does anyone know where I can find a tutorial on how to play *.wav files?

/\/\isanThr0p
Dec 26th, 2000, 10:08 PM
that's easy search this forum for the topic!
What do you want? just the sndplay api or something like direct sound to mix more than one wavefile?

nukem996
Dec 29th, 2000, 10:44 PM
ok two ways to do this. one is to goto components and
instert the mmcontrol "microsoft mutlimedia control 6.0."
where ever you want to play a sound put this code.
code:
cdsave.ShowOpen 'You dont have to put this in it just is to 'open a wav file
MMControl1.FileName = cdsave.FileName 'or put in ex '"c:\wav.wav" your file name
'stops mmcontrol
MMControl1.Command = "Stop"
'opens file
MMControl1.Command = "Open"
'plays file
MMControl1.Command = "Play"

thats one way and it can play most sound files but ive only used wav and mp3's.

if you want to do it threw api put this code in, but its hard
code:

Private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private 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
Private TheFileName As String, RecordMode As Boolean, dwreturn(1 To 4) As Long
Private ret As String * 128, OpenFile As Boolean, playingfile As Boolean

Dim tmp As String * 255
Dim lenShort As Long
Dim ShortPathAndFie As String
mciSendString "close mpeg", 0&, 0&, 0&
'check for an existing playing song
If playingfile = True Then mciSendString "stop mpeg", 0&, 0&, 0&

'close any open files first, to use this the mcierror function should not be used
If OpenFile = True Then mciSendString "close mpeg", 0&, 0&, 0&

'I have included a common Dialog box so you can choose an mp3
Open1.FileName = "" 'remove any previous filenames
Open1.flags = cdlOFNExplorer 'explorer interface
Open1.Filter = "Supported Files|*.mp3;*.wav" 'allow wav's or mp3's
Open1.ShowOpen
FileName = Open1.FileName
If FileName = "" Then Exit Sub 'If the user clicks cancel then nothing to open

lenShort = GetShortPathName(FileName, tmp, 255)
ShortPathAndFie = Left$(tmp, lenShort)
dwreturn(1) = mciSendString("open " & ShortPathAndFie & " type MPEGVideo Alias mpeg", 0&, 0&, 0&)

If dwreturn(1) <> 0 Then 'not success
MCIError (dwreturn(1))
Exit Sub
End If
OpenFile = True
cmdPlay_Click

Dim dwreturn(1 To 2) As Long
Dim ret As String * 128
'is the record mode turned on
If RecordMode = True Then 'yes
dwreturn(1) = mciSendString("open new type waveaudio Alias tune", 0&, 0&, 0&)
dwreturn(2) = mciSendString("record tune", 0&, 0, 0) 'play the mp3 after this one
For i = 1 To 2
If dwreturn(i) <> 0 Then
MCIError dwreturn(i)
Exit Sub
End If
Next i
End If
'Now play the open mp3 or wav
dwreturn(1) = mciSendString("play mpeg from 0", 0&, 0&, 0&)

If dwreturn(1) <> 0 Then
MCIError dwreturn(1)
Exit Sub
End If

note: i didnt do all this code i have talked to some one who helped me.

ull probly have to fix that a little too.
if ur a newbie i would use the first one cause api is hard. and u can make it invisable and tell it to do all the cmds. you can figer it out easly.

o yea put this in your code in the exit sub.
mmcontrol1
MMControl.Command = "Close"
api
mciSendString "close mpeg", 0&, 0&, 0&

drewski
Dec 30th, 2000, 07:47 PM
Sorry i havent been able to check the forum lately but I'll take a look at the control and check out the api code. thanks.