As the topic says… I’m pretty new with MonoGame and programming, and all the info I found online (with OpenTK, NVorbis etc. etc.) wasn’t really understandable for me, so…
Can anyone here please give me an EASY-TO-UNDERSTAND and STEP-BY-STEP sample how to use .OGG sound files to play a background song (and if possible also a sound effect) in C# / MonoGame using Visual Studio 2013 Desktop on Win7? Simplest methods preferred, of course.
ok I don’t have much time, but here we go, I hope it’s detailed enough.
In your MonoGame project you have the Content Pipeline tool.
You have probably used it before, but if you didn’t in your VS in the solution explorer you will find a folder called “Content” and in there the pipeline. Called content.mgcb.
Open the tool and in there you have to add an existing item. You can do that by right clicking on “Content” and selecting “Add -> Existing item” or on the corresponding icon above.
Select your .ogg file.
Now in your game code go to the class where you want to manage the music (or asset loading).
Make a new field for the SoundEffect
private SoundEffect mySoundEffect;
Now we need to initialize the sound effect.
Ideally we want to do this only once when the game is loaded.
In the main game file (yourprojectname.cs) you see a function which is called LoadContent.
/// LoadContent will be called once per game and is the place to load
/// all of your content.
protected override void LoadContent()
// TODO: use this.Content to load your game content here
This one is called at the start and you can call other functions from here.
In your soundmanager class you would ideally create another LoadContent function and somehow call if from the function mentioned above.
In there we add
`mySoundEffect = content.Load(“soundEffect”);
Note: If you created a folder in your content pipeline tool it would be “folder/soundEffect”. You don’t need to add the file ending here - don’t use “soundEffect.ogg”.
Ok great, so now we have loaded the SoundEffect into the game.
To play it we simply call
as far as I understand, the Content Pipeline converts sound effects to .XNB format before putting them into the debug/content and release/content folders, so what you describe is not really how to use .OGG, it’s just how to convert .OGG with the Content Pipeline (which can be done exactly the same way with .MP3, for example)… I would like to end up with a distributable game that contains native .OGG files.
Besides, what really is important for me is how to use .OGG for BACKGROUND MUSIC (song), because those files are usually converted to .WMA, and thus might not work on other devices as good as MonoGame’s .XNB.
Do you mean you want to read an ogg file directly without using the content pipeline ? Because if you are new to programming, the pipeline is the simplest way to do it. Otherwise you wil’ have to use an external library and it will likely be more complex.
Basically, I want to use background music (song) without ending up with a .WMA file in the distributable version of the game. .WAV is too big, .MP3 is licensed, so .OGG seems to be the only alternative.
So yes, this probably means not using the Content Pipeline. That’s why I’m asking for help here… I wouldn’t bother you all if it were ‘simple’ to do or to google.
DesktopGL uses OGG as its native music streaming format. Using OGG for sound effects natively is not supported in MonoGame at this time, mainly because there could be many tens of sound effects playing at any one time, and each of those are usually short in duration. Decoding multiple OGG sounds at once could be computationally too expensive.
Ok, forget the sound thing… what about just playing background music?
What exactly is DesktopGL? I thought MonoGame was an alternative to using OpenGL, and now I have to use GL again, just for sound?
Please explain (newbie, remember?)
Can you not just build the ogg files as resources in your project?
(Then do you need a player class, are there different ones for openGL and DirectX?)
MonoGame uses a graphics API. On Windows it uses DirectX or OpenGL, depending on which version of MonoGame you reference. The DirectX version uses Windows Media Foundation, which does not support OGG. The DesktopGL version has code to support playback of OGG streaming music.
Ah, ok… then just one last question:
As it seems, I’ve installed the Monogame ‘DirectX’ version. Where exactly can I get the DesktopGL version, and how do I uninstall the MonoGame DirectX and replace it with the DesktopGL version? Or can I install and use them parallel?
And after the switch, can I then play .OGG like Load[Song], or will it still be converted?
All versions are installed, you just switch to which type (dx, or opengl) you want when creating the project under the IDE.
I think some people have a solution containing many projects, with each project targeting different platforms.
Um… ok, then for a test, I would like to create a game that does NOT depend on Windows Media Foundation and uses a native .OGG file for background music, but still plays on Windows systems.
Where exactly do I switch the project? (Ive already selected 'MonoGame Windows Project, am I bound to it now?)
Newbie, please step-by-step…
I think create a new OpenGL project and copy everything across?
Might be a way to clone a project under a new template?
It might just entirely be one line, look at properties of your project file and conditional compiliation symbols in Build.
It can either be WINDOWS, LINUX etc.
Hm… it ‘might’? You mean I can’t create a Windows game that does not depend on Windows Media Foundation and uses .OGG? I have to select a specific system, and depending on that MonoGame chooses what to use?
Not 100% sure but it sounds like
DirectX project = using WMF
OpenGL project = using ogg (and others?)
Would be interesting to find out how to do a DirectX project but still use the “openGL” variants of media etc.
(If you go through monogame source code you will see a lot of #if WINDOWS etc wrapping certain parts, so if using windows you might be stuck with directX and WMF)
So, what this seems to come down to - nobody can tell me a simple way to use native .OGG files in a Windows game?!
the content pipeline converts fbx to xnb, converts textures to a proper format and converts sound to a better format for gaming.
Why would you need to have an .ogg file in the output binary folder? Just curious.
Well, it would be nice to have just one format for all platforms…
… can .WMA be used freely in games? Or do people have to pay a fee to Microsoft?
Start a DesktopGL project and add your ogg to the content pipeline, then load it like kosmonaut said. If you already have a DX project, switch the MonoGame.Framework.Windows reference to MonoGame.Framework.WindowsGL, change the pipeline tool target platform and fix output directories first. An ogg processed for OpenGL is still really an ogg internally I think. The pipeline tool picks appropriate formats for content depending on the platorm you’re targeting. If you’re only targeting windows, switching to OpenGL just to get ogg files is not something i’d recommend…