EMCIT
asked on
Play an Audio File with MS Access
I need to play an audio file in a loop when an MS Access app loads. How can I do this?
ASKER
Thank you. It opens the file fine but i need it to run in a loop.
How are you defining when to stop?
Do until...
Application.followhyperlin k...
Loop
Do until...
Application.followhyperlin
Loop
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried it in the timer interval and it works but it also launches Media Player each time and it takes the focus from the form. If it runs on a loop On Load the window can be minimized to get it out of the way. Or is there a method to play the wav file without launching the player?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can also use code like the sample below to play MDI or MP3 files.
Jim.
Private Declare Function mciSendString Lib "winmm.dll" Alias _
"mciSendStringA" (ByVal lpstrCommand As String, ByVal _
lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal _
hwndCallback As Long) As Long
Dim sMusicFile As String
Dim Play
Private Sub cmdPlayMusic_Click()
sMusicFile = Me.txtFileName.Text 'path has been included. Ex. "C:\3rdMan.mp3"
Play = mciSendString("play " & sMusicFile, 0&, 0, 0)
If Play <> 0 Then MsgBox "Can't PLAY!"
Me.cmdPlayMusic.Enabled = False
Me.cmdStopMusic.Enabled = True
End Sub
Private Sub cmdStopMusic_Click()
Play = mciSendString("close " & sMusicFile, 0&, 0, 0)
cmdPlayMusic.Enabled = True
cmdStopMusic.Enabled = False
End Sub
Jim.
Private Declare Function mciSendString Lib "winmm.dll" Alias _
"mciSendStringA" (ByVal lpstrCommand As String, ByVal _
lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal _
hwndCallback As Long) As Long
Dim sMusicFile As String
Dim Play
Private Sub cmdPlayMusic_Click()
sMusicFile = Me.txtFileName.Text 'path has been included. Ex. "C:\3rdMan.mp3"
Play = mciSendString("play " & sMusicFile, 0&, 0, 0)
If Play <> 0 Then MsgBox "Can't PLAY!"
Me.cmdPlayMusic.Enabled = False
Me.cmdStopMusic.Enabled = True
End Sub
Private Sub cmdStopMusic_Click()
Play = mciSendString("close " & sMusicFile, 0&, 0, 0)
cmdPlayMusic.Enabled = True
cmdStopMusic.Enabled = False
End Sub
BTW, here's a better link which has the possible flags that you can pass:
http://support.microsoft.com/kb/86281
You want SND_ASYNC + SND_LOOP
Jim.
http://support.microsoft.com/kb/86281
You want SND_ASYNC + SND_LOOP
Jim.
Will open the file.
Place that code in the open event of whatever form opens when the database starts up.