play wav or sound file on startup

  • Thread starter Thread starter JohnLute
  • Start date Start date
Hi, Gina! Thanks for the direction however the link returns "Cannot open web
page." Can you tell if the site is down...?
 
John,

Works for me... I did a copy/paste below...

'****************** Code Start *********************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Public Const pcsSYNC = 0 ' wait until sound is finished playing
Public Const pcsASYNC = 1 ' don't wait for finish
Public Const pcsNODEFAULT = 2 ' play no default sound if sound doesn't exist
Public Const pcsLOOP = 8 ' play sound in an infinite loop (until next
apiPlaySound)
Public Const pcsNOSTOP = 16 ' don't interrupt a playing sound

'Sound APIs
Private Declare Function apiPlaySound Lib "Winmm.dll" Alias "sndPlaySoundA"
_
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

'AVI APIs
Private Declare Function apimciSendString Lib "Winmm.dll" Alias
"mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Private Declare Function apimciGetErrorString Lib "Winmm.dll" _
Alias "mciGetErrorStringA" (ByVal dwError As Long, _
ByVal lpstrBuffer As String, ByVal uLength As Long) As Long


Function fPlayStuff(ByVal strFilename As String, _
Optional intPlayMode As Integer) As Long
'MUST pass a filename _with_ extension
'Supports Wav, AVI, MID type files
Dim lngRet As Long
Dim strTemp As String

Select Case LCase(fGetFileExt(strFilename))
Case "wav":
If Not IsMissing(intPlayMode) Then
lngRet = apiPlaySound(strFilename, intPlayMode)
Else
MsgBox "Must specify play mode."
Exit Function
End If
Case "avi", "mid":
strTemp = String$(256, 0)
lngRet = apimciSendString("play " & strFilename, strTemp, 255,
0)
End Select
fPlayStuff = lngRet
End Function
Function fStopStuff(ByVal strFilename As String)
'Stops a multimedia playback
Dim lngRet As Long
Dim strTemp As String
Select Case LCase(fGetFileExt(strFilename))
Case "Wav":
lngRet = apiPlaySound(0, pcsASYNC)
Case "avi", "mid":
strTemp = String$(256, 0)
lngRet = apimciSendString("stop " & strFilename, strTemp, 255,
0)
End Select
fStopStuff = lngRet
End Function

Private Function fGetFileExt(ByVal strFullPath As String) As String
Dim intPos As Integer, intLen As Integer
intLen = Len(strFullPath)
If intLen Then
For intPos = intLen To 1 Step -1
'Find the last \
If Mid$(strFullPath, intPos, 1) = "." Then
fGetFileExt = Mid$(strFullPath, intPos + 1)
Exit Function
End If
Next intPos
End If
End Function

Function fGetError(ByVal lngErrNum As Long) As String
' Translate the error code to a string
Dim lngx As Long
Dim strErr As String

strErr = String$(256, 0)
lngx = apimciGetErrorString(lngErrNum, strErr, 255)
strErr = Left$(strErr, Len(strErr) - 1)
fGetError = strErr
End Function
Function fatest()
Dim a As Long
a = fPlayStuff("C:\winnt\clock.avi")
'a = fStopStuff("C:\winnt\clock.avi")
End Function

'****************** Code End *********************
--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
Thanks, Gina. It wouldn't work for me so I just broke it down and hunted
through the site until I found it.


Youch! This is well beyond my comprehension! Is the first part intended to
be a module with the remainder to be in the on open event of a form?

First part:
'****************** Code Start *********************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Public Const pcsSYNC = 0 ' wait until sound is finished playing
Public Const pcsASYNC = 1 ' don't wait for finish
Public Const pcsNODEFAULT = 2 ' play no default sound if sound doesn't exist
Public Const pcsLOOP = 8 ' play sound in an infinite loop (until next
apiPlaySound)
Public Const pcsNOSTOP = 16 ' don't interrupt a playing sound

Second part:
 
Gina,

Please disregard my previous post. I see now where it belongs and I've
popped it into my startup Module.

I'm having trouble seeing how to direct it to the .WAV file I want to play.
Do I need to type in the complete path somewhere?

Muchas Gracias!
 
Ok, I think I get it now. I plugged in my wav file name here:

Function fatest()
Dim a As Long
a = fPlayStuff("C:\KEYSTONE_fe\Startup.wav")
'a = fStopStuff("C:\winnt\clock.avi")

End Function

It's not playing so I'm obviously doing something wrong. The debugger isn't
catching anything so I'm assuming I've got all the code in the right place.
Am I way off on where the path and file name go?
 
Hi, Gina! Please disregard all of my nonsense. I finally figured it out.
After 7 years of tinkering with Access I'm only now gettinginto functions. I
guess one can always be a newbie.

:)
 
Hi, Gina!

You mean that you don't stay up until the wee hours of the morning trying to
get this kind of stuff resolved?

I must be sick!

Anyway, thanks for your help. After I scouted around some more I stumbled on
other posts regarding this issue and learned some things here and there. It's
a really fun function to have.
 
Back
Top