This is a visual basic 6.0 wav sound player class that plays any selected sound file in .wav format. It has the filename property to select the file and play property to play the sound file.

msaqib -1 Tallied Votes 1K Views Share

This is a visual basic 6.0 wav sound player class that plays any selected sound file in .wav format. It has the filename property to select the file and play property to play the sound file. Visit http://www.mycplus.com for more codes.

Option Explicit 
Private mfilename As String 
Private mflags As Long 
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long 


Public Property Get filename() As String 
     filename = mfilename 
End Property 

Public Property Let filename(ByVal vnewvalue As String) 
     mfilename = vnewvalue 
End Property 

Public Property Get flags() As Long 
     flags = mflags 
End Property 

Public Property Let flags(ByVal vnewvalue As Long) 
     mflags = vnewvalue 
End Property 

Public Sub play() 
     Dim rc As Long 
     rc = sndPlaySound(mfilename, mflags) 
End Sub

Dani AI

Generated

Practical, no-fluff follow-up to the VB6 WAV player class by with answers to , and others.

A short usage pattern (pick a file, then play). Add the class as a Class Module, drop a Common Dialog control on a form, then call the class from the form code:

' On a form with a CommonDialog control (CommonDialog1)
Const SND_SYNC  = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Private Sub cmdPlay_Click()
    CommonDialog1.Filter = "Wave files (*.wav)|*.wav|All files (*.*)|*.*"
    CommonDialog1.ShowOpen
    If Len(CommonDialog1.FileName) > 0 Then
        Dim p As New WavPlayer   'replace WavPlayer with your class name
        p.filename = CommonDialog1.FileName
        p.flags = SND_ASYNC Or SND_FILENAME
        p.play
    End If
End Sub

Notes, pitfalls and alternatives: the class calls the simple WinMM API (sndPlaySound / PlaySound) so it is intended for waveform (.wav) playback and uses the SND_* flags for sync/async and filename behavior. For format support beyond WAV (MP3, etc.) consider using the MCI string interface (mciSendString), the Media Player ActiveX, or a modern library. (learn.microsoft.com)

Answers to : master volume can be adjusted with the WinMM volume APIs (waveOutSetVolume) or the mixer APIs for finer control; full-screen video is easiest with the Windows Media Player control (use its fullscreen support or resize it to the form client area at runtime); open PDF/DOC by launching the default handler (ShellExecute or Shell.Application). Also register OCX controls (comdlg32.ocx) on modern Windows and test paths with spaces and Unicode. (learn.microsoft.com)

karthik_02 0 Newbie Poster

how to select the file what we want..
where we have to place the code..

msaqib -3 Junior Poster in Training

Actually that is the implementation of a class module in VB, to play a specified file you will need to import this class into your project and then set the property filename to the files you want to play.

mankind33 0 Newbie Poster

Hi there, Thanks for the website and lots of appreciations.
I am a beginner in VB6.
I want to know how to put the systems master control of audio panel in my application of MMControl. and regulate the volume of out put.
How to make the videoscreen of this MMcontrol to full screen.!!
How to make the form fullscreen at run time with the controls proportionally expanded in the page.
How to open existing PDF or Doc files through this VB application.
I request an immediate reply. Thanks in advance and ATB.
If possible, please send a reply to my email id also :

surajcrj 0 Newbie Poster

This code is helpful to play your recorded sound with the .wav format

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.