Results 1 to 6 of 6

Thread: How to play wav file on clicking on a picture

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    India
    Posts
    158

    Question 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........????????

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    India
    Posts
    158

    Exclamation 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.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width