Results 1 to 2 of 2

Thread: [RESOLVED] Using Direct Sound

  1. #1

    Thread Starter
    Lively Member Brian M.'s Avatar
    Join Date
    Nov 2006
    Location
    Moberly MO
    Posts
    94

    Resolved [RESOLVED] Using Direct Sound

    Hello. I am trying to use direct sound to play a wav file, so I may animate a picture box while the wav file is playing. I have made a device object and a secondary buffer object and when I run the program I get an error message(see attached image), but after I click continue, the wav file plays and it plays every time I click the play wav button. I am using a test project to work out the bugs before I implement the direct sound in my other project. Below is the the code I am using. Can someone tell me what I am doing wrong? I would greatly appreciate it. The code needs a form named form1, and a button named xPlayButton.

    Code:
    Imports Microsoft.DirectX.DirectSound
    
    Public Class Form1
    
        Private Sub xPlayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xPlayButton.Click
    
            Dim sDevice As New Device
            sDevice.SetCooperativeLevel(Me, CooperativeLevel.Normal)
            Dim secBuffer As New SecondaryBuffer(My.Resources.b, My.Resources.b.Length, sDevice)
    
            secBuffer.Play(0, BufferPlayFlags.Default)
    
        End Sub
    
    End Class
    Attached Images Attached Images  

  2. #2

    Thread Starter
    Lively Member Brian M.'s Avatar
    Join Date
    Nov 2006
    Location
    Moberly MO
    Posts
    94

    Re: Using Direct Sound

    Well I figured out the reason my code was throwing an error. I didn't link to the Microsoft.DirectX library. I added this line:"Imports Microsoft.DirectX" and now it runs fine. I found that using the direct sound isn't really that hard. Dim a device object, dim a secondary buffer object, set the device cooperation level to the form that is calling direct sound, load the sound into the secondary buffer and viola' you are using direct sound. Easy as pie.

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