First you create a new resource file somewhere in your project. Use the Add -> New element
context menu in the project explorer to do that:
(yes, sorry, that's in german.)
Once you created your resource file you can double-click on it in the project explorer and add resources to it. I added a .wav
file called out.wav
. This could be your .mp3
file.
Next you just have to access that stream in Code. Adding the resource file also generates some code which let's you access that file as a stream. Usage e.g.:
using System;
using System.IO;
using System.Text;
namespace ResourceTest
{
class Program
{
static void Main(string[] args)
{
//Create a memory stream to read the file into..
MemoryStream outStream = new MemoryStream();
//Copy our _out.wav File
SomeResource._out.CopyTo(outStream);
//Also possible:
//SomeResource.ResourceManager.GetStream("out.wav")...
//Read into a byte array.
byte[] file_bytes = outStream.ToArray();
//Close it
outStream.Close();
//Do something with file_bytes..
}
}
}
Now that you've embedded your ressource in a ressource file, it's always accessible (i.e. the resource always gets copied in your compiled binary)