I place all my pipeline generated content into a single .pak file and load using the following custom Content loader:
public class PAKContentManager : ContentManager
private GraphicsDevice device;
private IGraphicsDeviceService graphicsDeviceService;
private IServiceProvider serviceProvider;
public PAKContentManager(ContentManager baseContentManager, string path, GraphicsDevice graphicDevice) : base(baseContentManager.ServiceProvider, "Content")
device = graphicDevice;
serviceProvider = baseContentManager.ServiceProvider;
_basePath = path;
RootDirectory = path;
protected override Stream OpenStream(string assetName)
return FilePacker.GetFileStream(_basePath, assetName);
FilePacker.GetFileStream() returns a stream that reads a portion of the .PAK file as if it was a stream of its own.
This works pretty well. Except for Songs (probably videos, have not checked). These file types fail because the .xnb is not the actual song, just a placeholder that refers to the song, and the MonoGame library does not seem to call the OpenStream method for the actual song file in the .PAK. I get around it by extracting the song files to a temp folder. But I really would prefer to not have to do that.
I am using Windows/DirectX, and Android with the latest 3.8 nuget package. They both have the same issue.
Anyone know a better way to do this?
Primarily because the app is multi game and new games can be added and downloaded via this pak file. The delivery is on a closed network with hundreds of clients. The pak file is compressed to reduce transfer time over wifi when literally hundreds of clients need to get updated. and each pak file contains everything needed for one entire game. Also it is easier to check the digital signature of a single file to determine if an update is needed and easier to download a single file when a new game becomes available.
Otherwise there would be literally thousands of files to deal with and manage.
But debate about design aside, this decision was made some time ago. The local temp file has been working for a while. But I was just wondering if someone with more knowledge of the inner workings might have a better idea.
From what I can tell you’re SoL. The NVorbis implementation of Song uses an OggStream to play the music and this is the only constructor for it:
public OggStream(string filename, Action finishedAction = null, int bufferCount = DefaultBufferCount)
oggFileName = filename;
FinishedAction = finishedAction;
BufferCount = bufferCount;
alBufferIds = AL.GenBuffers(bufferCount);
ALHelper.CheckError("Failed to generate buffers.");
alSourceId = OpenALSoundController.Instance.ReserveSource();
OggStreamer.Instance.XRam.SetBufferMode(BufferCount, ref alBufferIds, XRamExtension.XRamStorage.Hardware);
ALHelper.CheckError("Failed to activate Xram.");
Volume = 1;