locked
using 'Resources' RRS feed

  • Question

  • hey,

     

    I downloaded DirectX SDK yesterday and got to work adding sound on a new project... it works alright...

    but now I want to have sound files included into the project (as opposed to having to be loaded from the hard-drive)

     

    this works :

     

    Microsoft.DirectX.AudioVideoPlayback.Audio DXAsteroidDestroyed = new Microsoft.DirectX.AudioVideoPlayback.Audio("C:\\Games\\Asteroids_C#\\AsteroidDestroyed.wav");

     

    but I would like :

    "C:\\Games\\Asteroids_C#\\AsteroidDestroyed.wav"

     

    to be part of the compiled file, not a separate file ... I've seen "Resources" flouted about but can't seem to use it...

     

    any ideas?

     

    BadButBit

    Tuesday, September 4, 2007 12:34 AM

All replies

  • In order to add the wav file to your project you can embed it manually... or open up your project properties, select the Resources tab and choose Add Resource -> Add Existing File and find your file to add it to the project.
     
    Once you've added it you can access that file it's simply a matter of accessing the stream in your apps resources which can be accessed like so:

     

    Code Snippet
    YourRootNameSpace.Properties.Resources.ResourceName

     

     

    One problem with this method is that that resource is actually returned to you as a memory stream which means you may be responsible for reading it and putting it into a form that your audio player can play.

     

    You could always use the audio player built into the 2.0 framework though:

     

    Code Snippet

     

    System.Media.SoundPlayer player = new System.Media.SoundPlayer(YourRootNameSpace.Properties.Properties.Resources.ResourceName);

    player.Play();

     

     

    Tuesday, September 4, 2007 12:51 AM
  • hey,

    thanks for your suggestion.

     

    I have the files in the resources menu of C#... which is a good thing but using them in DirectX's audio player seems to be a problem because it only accepts a filename in the form of a string ... so I still don't know how to load it into DX

     

    BadButBit

    Tuesday, September 4, 2007 1:05 AM
  • Tuesday, September 4, 2007 5:06 AM
  • In that case you’ll need to go with another sound playing mechanism such as DirectSound.

     

    If you've got the DirectX SDK installed take a look at some of the DirectSound examples.

    Tuesday, September 4, 2007 5:31 AM
  •  

    hi,

    thank... I read that article and downloaded the source code... then used it in my application.  but the media player is a single entity... kind of 'one-handed'.  I'm just learing C# and working on asteroids.... it works fine with Direct X only I but using many instances of the same player amounts to using the same player (I guess I'm getting pointers to the same driver...) so when the alien appears and the siren (siren.wav) goes off you only hear it until the player shoots, then the bullet.wav is heard and ends all sound until the next bullet or crash.... so when you're playing.. you only hear bullets.

    thanks for the idea, another tool in the tool-belt, but not for this job.

    BadButBit

    Tuesday, September 4, 2007 1:57 PM