How do I play a .wav file from Resources?

Visual Basic 2005 Express Edition:

This works, but, I need to get the .wav file from Resources:
My.Computer.Audio.Play("C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\OrthoLabRx\OrthoLabRx\Resources\PodVwBy.wav")

I placed the .wav file in Resources, but, I can't seem to access it from there.
This does not work:
My.Computer.Audio.Play(My.Resources.PodVwBy)
It says "value of type 'System.IO.UnmangedMemoryStream' cannot be converted to 'String'.

This worked, but, instead of a click, it played a grinding noise:
Dim sndPing As New SoundPlayer(My.Resources.PodVwBy)
sndPing.Play()
My.Computer.Audio.Play(My.Resources.PodVwBy)




Answer this question

How do I play a .wav file from Resources?

  • janiv

    The following plays a resource named dizzymis.wav. Resource, not file.

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

    My.Computer.Audio.Play(PLAYSOUND("dizzymis"), AudioPlayMode.Background)

    End Sub

    Function PLAYSOUND(ByVal resname As String) As System.IO.MemoryStream

    Dim obj As Object = My.Resources.ResourceManager.GetObject(resname)

    Dim b As System.IO.MemoryStream = obj

    Return b

    End Function



  • Ronak

    furjaw wrote:

    My.Computer.Audio.Play(My.Resources.clickerx, AudioPlayMode.WaitToComplete)

    That did the trick!

    Thanks to everyone who contributed! I couldn't have done it without you!



    I added "klikk.wav" to my resources. But when I add this code to a button:

    My.Computer.Audio.Play(My.Resources.klikk, AudioPlayMode.WaitToComplete)

    It says klikk is not a member of resources.


  • eisebs

    hi,

    this page has a good example

    http://msdn.microsoft.com/vstudio/express/vb/learning/default.aspx

    hope this helps



  • Michelle Cheng

    My.Computer.Audio.Play(My.Resources.clickerx, AudioPlayMode.WaitToComplete)

    That did the trick!

    Thanks to everyone who contributed!  I couldn't have done it without you!

     


  • How do I play a .wav file from Resources?