|
-
Feb 16th, 2010, 09:15 AM
#1
Thread Starter
Addicted Member
How to play wav file on clicking on a picture
Guys plz help me on the way...... i want to play a wave/mp3 file on clicking of a picture......how to do it........????????
-
Feb 16th, 2010, 09:22 AM
#2
Re: How to play wav file on clicking on a picture
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
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 16th, 2010, 09:28 AM
#3
Re: How to play wav file on clicking on a picture
And without using a control, you can search this forum for the following: sndPlaySound, PlaySound, mciSendString
-
Feb 16th, 2010, 09:36 AM
#4
Re: How to play wav file on clicking on a picture
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
Last edited by RhinoBull; Feb 16th, 2010 at 10:59 AM.
Reason: function declaration added
-
Feb 16th, 2010, 09:54 AM
#5
Thread Starter
Addicted Member
Re: How to play wav file on clicking on a picture
what components/references should be checked on to play media files, as i am getting error in the said coding.........Plz help.
-
Feb 16th, 2010, 09:56 AM
#6
Re: How to play wav file on clicking on a picture
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|