Jump to content

MissingMethodException - playing WAV from resource


Recommended Posts

Guest sagewithin
Posted

Hi everyone:

I'm trying to play a WAV file that is an embedded resource, but I am getting a MissingMethodException. The code is below. Can anyone help me figure out why? This is a smartphone 2003 app being built with VB.NET. Thanks in advance!

Public Class SoundRes

'API call for playing sounds in memory

Private Declare Function PlaySound Lib "winmm.dll" (ByVal data() As Byte, _

ByVal hMod As IntPtr, ByVal hwFlags As Integer) As Integer

Private Const SND_ASYNC As Integer = &H1 'Play asynchronously

Private Const SND_MEMORY As Integer = &H4 'Play wav in memory

Private Const SND_NODEFAULT As Integer = &H2 'Play wav in memory

Shared Sub New()

Dim WavStrm As IO.Stream = _

Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("FriendorLover.HIT.WAV")

ReDim ClickSound(CType(WavStrm.Length, Integer))

WavStrm.Read(ClickSound, 0, Int(CType(WavStrm.Length, Integer)))

End Sub

'Play embedded .wav resource

Public Sub PlayWav(ByVal WavResource As Byte())

PlaySound(WavResource, IntPtr.Zero, SND_ASYNC Or SND_MEMORY Or SND_NODEFAULT)

End Sub

End Class

Then to play the sound:

Dim mysound As New SoundRes

mysound.PlayWav(ClickSound)

Guest Peter Foot
Posted
Hi everyone:

I'm trying to play a WAV file that is an embedded resource, but I am getting a MissingMethodException.  The code is below.  Can anyone help me figure out why?  This is a smartphone 2003 app being built with VB.NET.  Thanks in advance!

Public Class SoundRes

    'API call for playing sounds in memory

    Private Declare Function PlaySound Lib "winmm.dll" (ByVal data() As Byte, _

        ByVal hMod As IntPtr, ByVal hwFlags As Integer) As Integer

    Private Const SND_ASYNC As Integer = &H1        'Play asynchronously

    Private Const SND_MEMORY As Integer = &H4      'Play wav in memory

    Private Const SND_NODEFAULT As Integer = &H2      'Play wav in memory

    Shared Sub New()

        Dim WavStrm As IO.Stream = _

            Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("FriendorLover.HIT.WAV")

        ReDim ClickSound(CType(WavStrm.Length, Integer))

        WavStrm.Read(ClickSound, 0, Int(CType(WavStrm.Length, Integer)))

    End Sub

    'Play embedded .wav resource

    Public Sub PlayWav(ByVal WavResource As Byte())

        PlaySound(WavResource, IntPtr.Zero, SND_ASYNC Or SND_MEMORY Or SND_NODEFAULT)

    End Sub

End Class

Then to play the sound:

        Dim mysound As New SoundRes

        mysound.PlayWav(ClickSound)

<{POST_SNAPBACK}>

Change your P/Invoke to

Private Declare Function PlaySound Lib "coredll.dll" (ByVal data() As Byte, _

ByVal hMod As IntPtr, ByVal hwFlags As Integer) As Integer

The method is in coredll.dll on Windows CE

Peter

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.