PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Play Multiple Sounds With Managed DirectX (2003 and 2005)-VBForums
Results 1 to 2 of 2

Thread: Play Multiple Sounds With Managed DirectX (2003 and 2005)

  1. #1

    Thread Starter
    "The" RedHeadedLefty
    Join Date
    Aug 2005
    Location
    College Station, TX Preferred Nickname: Gig Current Mood: Just Peachy Turnons: String Manipulation
    Posts
    4,495

    Play Multiple Sounds With Managed DirectX (2003 and 2005)

    The advantage of using DirectX to play audio is that you can have multiple sounds play at the same time, as well as support for all sorts of audio file types. It is relatively simple one you get past the initial hurdles. The code is not complex, and can be found in examples around, but I ran into a few problems, and thought I would be handy for anyone else who may wish to use it.

    In order to play a sound using DirectX, you must first have the DirectX SDK (that contains managed extensions), which includes the DLL files that you will need to reference inside of your project.

    If you are wanting just sound, you have to add a reference to "Microsoft.DirectX.AudioVideoPlayback", and "Microsoft.DirectX.DirectSound". These are both 1.1 assemblies for use in 2003, but tested in 2005 and it worked, however with a catch.

    There is a problem with a LoaderLock exception when using 2005, and a description and solution to the problem was found here. In short, you have to disable the loader lock MDA by going to :
    "Debug > Exceptions, Open the Managed Debugging Assistants tree node and uncheck Loader Lock. This setting is per solution so it will only affect this solution."
    Once that is done, you should not run into an exception anymore, and it will not affect the project anyway since it is only displayed while debugging, and will not occur in release mode. It is a known issue by Microsoft, but probably won't be fixed since everything is moving to the XNA framework for use with 2.0.

    Anyways, back to the code. As I said before, its simple once you get done with all that. Below plays two sounds (same file) with a 5 second delay between them. I just used a sample mp3 file (you can use wav or any other sound format that directx recognizes), and the same song played twice at the same time (one being 5 seconds behind the other). This is not meant to be the exact code you would use, just sample to show that it works...
    VB Code:
    1. Dim MySound1 As New Microsoft.DirectX.AudioVideoPlayback.Audio("c:\test.mp3")
    2.         Dim MySound2 As New Microsoft.DirectX.AudioVideoPlayback.Audio("c:\test.mp3")
    3.         MySound1.Play()
    4.         System.Threading.Thread.Sleep(5000)
    5.         MySound2.Play()
    6.         System.Threading.Thread.Sleep(5000)
    7.         MySound1.Stop()
    8.         MySound2.Stop()
    Last edited by gigemboy; Aug 17th, 2006 at 02:31 AM.

  2. #2
    New Member
    Join Date
    Aug 2006
    Posts
    1

    Re: Play Multiple Sounds With Managed DirectX (2003 and 2005)

    Hi There,

    This is my first reply, and I'm new to this site.

    There is an easier way in Visual Basic 2005 to get past the loader lock error.

    When you ad The Microsoft.AudioVideoPlayback.dll to your resources, remember to also ad the Microsoft.Directx.dll file to your resources.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width