in my application, i need to add a sound.how can i add a sound button?
after click a button it will play the sound.no need a stop button..
thanks in advance..

Public Declare Function PlaySound Lib "winmm.dll" (ByVal pszSound As String, ByVal hmod As IntPtr, ByVal fdwSound As Integer) As Boolean
    'Public Declare Function PlaySound Lib "winmm.dll" (ByVal pszSound As Byte(), ByVal hmod As IntPtr, ByVal fdwSound As SoundFlags) As Boolean
    Public Enum SoundFlags As Integer
        ''' <summary>
        ''' The sound is played synchronously, and PlaySound returns after
        ''' the sound event completes. This is the default behavior.
        ''' </summary>
        SND_SYNC = &H0

        ''' <summary>
        ''' The sound is played asynchronously and PlaySound returns
        ''' immediately after beginning the sound. To terminate an
        ''' asynchronously played waveform sound, call PlaySound with
        ''' pszSound set to NULL.
        ''' </summary>
        SND_ASYNC = &H1

        ''' <summary>
        ''' No default sound event is used. If the sound cannot be found,
        ''' PlaySound returns silently without playing the default sound.
        ''' </summary>
        SND_NODEFAULT = &H2

        ''' <summary>
        ''' The pszSound parameter points to a sound loaded in memory.
        ''' </summary>
        SND_MEMORY = &H4

        ''' <summary>
        ''' The sound plays repeatedly until PlaySound is called again
        ''' with the pszSound parameter set to NULL. If this flag is
        ''' set, you must also set the SND_ASYNC flag.
        ''' </summary>
        SND_LOOP = &H8

        ''' <summary>
        ''' The specified sound event will yield to another sound event
        ''' that is already playing. If a sound cannot be played because
        ''' the resource needed to generate that sound is busy playing
        ''' another sound, the function immediately returns False without
        ''' playing the requested sound.
        ''' </summary>
        ''' <remarks>If this flag is not specified, PlaySound attempts
        ''' to stop the currently playing sound so that the device can
        ''' be used to play the new sound.
        ''' </remarks>
        SND_NOSTOP = &H10

        ''' <summary>
        ''' Stop playing wave
        ''' </summary>
        SND_PURGE = &H40

        ''' <summary>
        ''' If the driver is busy, return immediately without playing
        ''' the sound.
        ''' </summary>
        SND_NOWAIT = &H2000

        ''' <summary>
        ''' The pszSound parameter is a system-event alias in the
        ''' registry or the WIN.INI file. Do not use with either
        ''' SND_FILENAME or SND_RESOURCE.
        ''' </summary>
        SND_ALIAS = &H10000

        ''' <summary>
        ''' The pszSound parameter is a file name. If the file cannot be
        ''' found, the function plays the default sound unless the
        ''' SND_NODEFAULT flag is set.
        ''' </summary>
        SND_FILENAME = &H20000

        ''' <summary>
        ''' The pszSound parameter is a resource identifier; hmod must
        ''' identify the instance that contains the resource.
        ''' </summary>
        SND_RESOURCE = &H40004
    End Enum

    Public Sub Play(ByVal strFileName As String)
        PlaySound(strFileName, IntPtr.Zero, SoundFlags.SND_FILENAME Or SoundFlags.SND_ASYNC)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Play("C:\DÖNALd.wav")
    End Sub

why afta i run the file there an errors in line "PlaySound(strFileName, IntPtr.Zero, SoundFlags.SND_FILENAME Or SoundFlags.SND_ASYNC) End Sub"

An unhandled exception of type 'System.MissingMethodException' occurred in LearnJapaneseTutorialSystem.exe
any mistakes dat i did?

i post the program, try it.

i cant open the file.wat extension isit?

what u means cant open?
cant to open attachment file or wave (.wav) file?

cant open the attachment file.

okay..thank you for the program.i donwload it again..so,as u done it in windows application.isit the coding for windows app n smartdevice app is the same?because when i try it in smartdevice application,there an error in line afta i run
PlaySound(strFileName, IntPtr.Zero, SoundFlags.SND_FILENAME Or SoundFlags.SND_ASYNC)

the error sed "An unhandled exception of type 'System.MissingMethodException' occurred in SmartDeviceApplication2.exe"

this for windows application.
i repost the program.

im doing myproject in smartdevice application.isit i stil can using the same coding?because it seems still having an error on PlaySound(strFileName, IntPtr.Zero, SoundFlags.SND_FILENAME Or SoundFlags.SND_ASYNC)
which it sed "An unhandled exception of type 'System.MissingMethodException' occurred in SmartDeviceApplication2.exe"

well i never do this in smart device...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim mySound As New Sound("\windows\alarm1.wav")

mySound.Play()

End Sub
End Class

Public Class Sound

Private m_soundBytes() As Byte

Private m_fileName As String

Public Declare Function WCE_PlaySound Lib "CoreDll.dll" Alias "PlaySound" (ByVal szSound As String, ByVal hMod As IntPtr, ByVal flags As Integer) As Integer

Public Declare Function WCE_PlaySoundBytes Lib "CoreDll.dll" Alias "PlaySound" (ByVal szSound() As Byte, ByVal hMod As IntPtr, ByVal flags As Integer) As Integer

Private Enum Flags

SND_SYNC = &H0 ' play synchronously (default)

SND_ASYNC = &H1 ' play asynchronously

SND_NODEFAULT = &H2 ' silence (!default) if sound not found

SND_MEMORY = &H4 ' pszSound points to a memory file

SND_LOOP = &H8 ' loop the sound until next sndPlaySound

SND_NOSTOP = &H10 ' don't stop any currently playing sound

SND_NOWAIT = &H2000 ' don't wait if the driver is busy

SND_ALIAS = &H10000 ' name is a registry alias

SND_ALIAS_ID = &H110000 ' alias is a predefined ID

SND_FILENAME = &H20000 ' name is file name

SND_RESOURCE = &H40004 ' name is resource name or atom

End Enum

' Construct the Sound object to play sound data from the specified file.

Public Sub New(ByVal fileName As String)

m_fileName = fileName

End Sub

' Construct the Sound object to play sound data from the specified stream.

Public Sub New(ByVal stream As System.IO.Stream)

' read the data from the stream

m_soundBytes = New Byte(stream.Length) {}

stream.Read(m_soundBytes, 0, Fix(stream.Length))

End Sub 'New

' Play the sound

Public Sub Play()

' If a file name has been registered, call WCE_PlaySound,

' otherwise call WCE_PlaySoundBytes.

If Not (m_fileName Is Nothing) Then

WCE_PlaySound(m_fileName, IntPtr.Zero, Fix(Flags.SND_SYNC Or Flags.SND_FILENAME))

Else

WCE_PlaySoundBytes(m_soundBytes, IntPtr.Zero, Fix(Flags.SND_ASYNC Or Flags.SND_MEMORY))

End If

End Sub

to more clearly see this link

THANK YOU Jx_Man for the link.my problem solve =)

you're welcome...
Happy coding :)

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.