Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Request help with getting sound from resources  (Read 3531 times)

0 Members and 1 Guest are viewing this topic.

coogison

  • Newbie
  • *
  • Posts: 2
    • View Profile
Request help with getting sound from resources
« on: January 27, 2014, 09:01:33 pm »
Hello, i wrote small unit which allows me to create textures, sounds and fonts i am using in my small application.

Fonts and Images working fine like this examples (its not the best way probably, but it works :))

    public static class Constants
    {
        // fonts
        public static Font textFont = GetFont("frquad");  

        public static Font GetFont(String AResourceName)
        {
            byte[] bytes = (byte[])Properties.Resources.ResourceManager.GetObject(AResourceName);
            MemoryStream str = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(str);
            writer.Write(bytes);
            str.Position = 0;
            return new Font(str);
        }
    }

.... but i cant load sound in a similar way. All the time i failed creating SoundBuffer from stream which i want to load from resources.

Any help appreciated.

Thanks a lot,

coogison
« Last Edit: January 27, 2014, 09:03:09 pm by coogison »

Aaron Goulet

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Request help with getting sound from resources
« Reply #1 on: January 27, 2014, 09:34:46 pm »
For getting an input stream from an embedded resource, try this instead:

Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);

The name of your resource using this method may be different, however; there is another method called GetManifestResourceNames() which you can use while debugging if you run into any problems.

krzat

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Request help with getting sound from resources
« Reply #2 on: January 27, 2014, 09:37:21 pm »
Can be related to this: https://github.com/SFML/SFML.Net/pull/21
A crappy workaround would be to save that stream to temporary file and pass the filename instead.
SFML.Utils - useful extensions for SFML.Net

Aaron Goulet

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Request help with getting sound from resources
« Reply #3 on: January 27, 2014, 09:41:31 pm »
The method I posted seems to work with Visual C# .NET, but keep in mind that it won't necessarily work on other platforms (I haven't even looked at the Mono APIs yet).

coogison

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Request help with getting sound from resources
« Reply #4 on: January 27, 2014, 11:15:13 pm »
Thank yuo all for pointing me to the right direction. But problem was somewhere else.

I didnt copy all sounds dll-s into application directory, and because i encountered this strange behaviour during application initalization it was a bit ungly to solve it out. (hidden error message)

Aaron Goulet

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Request help with getting sound from resources
« Reply #5 on: January 27, 2014, 11:58:07 pm »
No problem, glad that you got it figured out!