How to embed and play wav files into a form?

John Baker

Registered User.
Local time
Today, 09:32
Joined
Apr 13, 2005
Messages
35
Greetings:

This is a new area for me and I am struggling with how to approach the solution. Have searched the archives but still can't figure it out....

I have a database that stores call center coaching events. I would like to insert a wav file (recorded conversation) into each record and be able to play the wav file when the record is current in the form.

Any guidance or suggestions would be greatly appreciated.

Thanks!
John
 
I would recommend NOT embedding any media file into your database, you will find that this causes tremendous bloat. I would store the file outside your database and simply store the path i.e. "C:\Program Files\File.wav", in your table for the particular record. There is a nice function sample in this post that will get you started on how to call the wav file.

hope this helps,

Scott
 
create a Module called playwavefile input this code:
Code:
Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal filename As String, ByVal snd_async As Long) As Long
Public Function playwavefile(sWavFile As String)
If apisndPlaySound(sWavFile, 1) = 0 Then
MsgBox "The Sound Did Not Play!"
End If
End Function

Public Sub PlayWaveFile_Cord()
Call playwavefile("C:\name and location of wave file.wav")
End Sub

to call the wave file from a form place the following code in anevent procedure:
Code:
Call PlayWaveFile_Cord
 
bonekrusher said:
create a Module called playwavefile input this code:
Code:
Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal filename As String, ByVal snd_async As Long) As Long
Public Function playwavefile(sWavFile As String)
If apisndPlaySound(sWavFile, 1) = 0 Then
MsgBox "The Sound Did Not Play!"
End If
End Function

Public Sub PlayWaveFile_Cord()
Call playwavefile("C:\name and location of wave file.wav")
End Sub

to call the wave file from a form place the following code in anevent procedure:
Code:
Call PlayWaveFile_Cord
Why not post the link to where you found the code? You would not want somebody to think that you actually created that function; would you? :p
how do i use windows media player on my form? - 2005
Adding a sound on exiting the database - 2003
 
G, good point.; only trying to help. I'll do that next time.

Bones
 
Thanks, bone and g. I am able to play a file using the 'PlayWaveFile' function that you suggested - works just fine!

Now, I am interested in using the Windows Media Player control. I added the control to my form and I used the code in the link you provided:

md.FileName = "Name of File to be Played"
md.Play

However, I am getting a runtime error:

Runtime error -2147467259 (8004005)
Automation error
Unspecified error

Any help or guidance would be appreciated!

Thanks,
John
 
ok try this. Place the Media player in a form. On the Enter Event procedure use this code:


Code:
Dim filename As String
filename = ("C:\nameoffile.wmv")
Me.WindowsMediaPlayer0.URL = filename


Bones
 
Thanks for the suggestion, bone. However, I get a different error when the following line of code tries to execute:

Me.WindowsMediaPlayer0.URL = filename

Run time error '438'
Object does not support this procedure or method.

I suspect I may have a registry problem but can't figure out how to solve!
 
Success - Finally!!

After additional research in various forums, I have finally found a solution. The following link describes how to start an application using a Shell Execute function. I placed a command button on my form that makes a call to this function, passing the name of the wav file. The end result is that Windows Media Player is executed and I am able to control start/pause/stop as I listen to the file.

http://www.mvps.org/access/api/api0018.htm
 
where "WindowsMediaPlayer0" is the name of YOUR media player. if the name your media player control is "MD" then use this line:

Me.MD.URL = filename
 
Still does not work for me, bone. I continue to get the following error when I try to incorporate the Windows Media Player control into my form.

Run time error '438'
Object does not support this procedure or method.

The only way I am able to launch Windows Media Player and play wav files is by making a call to the shell execute function that I described in my previous post.

Run time error '438'
Object does not support this procedure or method.

John
 
Yes, I have set a reference to 'Windows Media Player' in my project.
 
I've attached a file to get you started. I comprised the code from numerous post and also used GHudson "Browser" Example for the code.

Hope this helps.
 

Attachments

Here is a better version. I stripped down some code I had in there that was not needed. This will help you understand how I did it.

Good Luck
 

Attachments

Hi,

How to set path directly to run the file once the form opens ?
I tried showing direct path of file to run but no use.

Regards,
Ashfaque
 
Get rid of the open form event. I added this to reset the url to null:

Me.WMP.URL = ""

just delete it.

Bones
 
No. Instead of deleting, I just added the path of file that need to run as shown below and it worked.

Me.WMP.URL = "E:\gcf\MPEGAV\AVSEQ01.dat"

thanks with regards,
Ashfaque
 
Module 1
Option Compare Database

Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

' for playing sounds (each one is listed below in detail)
Global Const KEY_RETURN = &HD
Global Const SND_SYNC = &H0
Global Const SND_ASYNC = &H1
Global Const SND_NODEFAULT = &H2
Global Const SND_LOOP = &H8
Global Const SND_NOSTOP = &H10
'-----------------------------------------------------------
Module 2
Function Import_Ads()



' SND_LOOP
' The sound will continue to play repeatedly until

' sndPlaySound is called again with the lpszSoundName$
' parameter set to null. You must also specify the
' SND_ASYNC flag to loop sounds.

' SND_NOSTOP
' If a sound is currently playing, the function will
' immediately return False without playing the requested
' sound.

On Error GoTo ImportAds_Resume

DoCmd.DeleteObject acTable, "Unisys Ads"

ImportAds_Resume:
Dim Message As String
DoCmd.SetWarnings False

'Do While Message <> "1"
x% = sndPlaySound("\\10.25.13.180\aimstuff\jeopardy[1].wav", SND_ASYNC)
DoCmd.TransferText acImportFixed, "Unisys Ads Import", "Unisys Ads", "l:\mar2006.txt", False, ""

DoCmd.OpenQuery "Trim Spaces from Unisys Ad #", acViewNormal, acReadOnly
DoCmd.SetWarnings True
DoCmd.DeleteObject acTable, "mar2006_ImportErrors"

'----------------- Put this in a sub to play a wav file ----
'x% = sndPlaySound("c:\documents and settings\dheichelbech\my documents\my music\fdone10[1].wav", SND_SYNC)
'-----------------------------------------------------------

' Specifies options for playing the sound using one or more of the following flags:
' SND_SYNC
' The sound is played synchronously and the function does
' not return until the sound ends.

' SND_ASYNC
' The sound is played asynchronously and the function
' returns immediately after beginning the sound.

' SND_NODEFAULT
' If the sound cannot be found, the function returns
' silently without playing the default sound.


x% = sndPlaySound("c:\documents and settings\dheichelbech\my documents\my music\fdone10[1].wav", SND_ASYNC)
Message = MsgBox("Process Completed")

ImportAds_Exit:
Exit Function

Import_Unisys_Ads_Err:
MsgBox Error$
Resume ImportAds_Exit
'Loop
End Function


The song plays when the button is clicked
 
This isn't working for me - why?

bonekrusher said:
create a Module called playwavefile input this code:
Code:
Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal filename As String, ByVal snd_async As Long) As Long
Public Function playwavefile(sWavFile As String)
If apisndPlaySound(sWavFile, 1) = 0 Then
MsgBox "The Sound Did Not Play!"
End If
End Function

Public Sub PlayWaveFile_Cord()
Call playwavefile("C:\name and location of wave file.wav")
End Sub

to call the wave file from a form place the following code in anevent procedure:
Code:
Call PlayWaveFile_Cord




This would be great if I could get it to work but I can't! I am a novice though...

I have a text box called Hyperlink which has a hyperlink to the wav file. I have a continuous form with a different hyperlink in each record and a cmd button which I have Call PlayWavefile linked to.
This is my adapted version of the above which doesn't work:

=========
Option Compare Database
Option Explicit

'PlayWaveFile
Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal filename As String, ByVal snd_async As Long) As Long

Public Function PlayWaveFile(sWavFile As String)

If apisndPlaySound(sWavFile, 1) = 0 Then
'MsgBox "The Sound Did Not Play!"
End If

End Function

Public Sub PlayWaveFile_Cord()

Dim wavfile As String

wavfile = [Forms]![form1].[Hyperlink]
'wavfile = me.Hyperlink doesn't work

Call PlayWaveFile("wavfile")

End Sub

=========

Can anyone help?:o
 

Users who are viewing this thread

Back
Top Bottom