Guys plz help me on the way...... i want to play a wave/mp3 file on clicking of a picture......how to do it........????????
Printable View
Guys plz help me on the way...... i want to play a wave/mp3 file on clicking of a picture......how to do it........????????
You can achieve using the MMC (multimedia control). I have named the mmc control as mmcAudio in the code below.
Here is a very basic example. Please amend it to suit your needs.
Code:Private Sub Form_Load()
'~~> Preparing the audio control
mmcAudio.Notify = False
mmcAudio.Wait = True
mmcAudio.Shareable = False
mmcAudio.Command = "Close"
End Sub
'~~> Play MP3 file when the picture is clicked
Private Sub MyPic_Click()
'~~> Change this to your relevant mp3 file
mmcAudio.FileName = "C:\MyFile.Mp3"
mmcAudio.Command = "Open"
mmcAudio.Command = "Play"
End Sub
Private Sub Form_Unload(Cancel As Integer)
'~~> Close the multimedia device.
mmcAudio.Command = "Close"
End Sub
And without using a control, you can search this forum for the following: sndPlaySound, PlaySound, mciSendString
I had PlaySound snippet handy so here we go:
Code:Option Explicit
Private Const SND_FILENAME = &H20000
Private Const SND_ASYNC = &H1
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 Picture1_Click()
PlaySound "C:\Windows\Media\ding.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
End Sub
what components/references should be checked on to play media files, as i am getting error in the said coding.........Plz help.
For koolsid's suggestion, press Ctrl+T while in design mode and find the multimedia audio component.
For RhinoBull's suggestion, you'll need the API declaration & constants
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 Const SND_FILENAME As Long = &H20000
Private Const SND_ASYNC As Long = &H1