mp3 in monogame c#

Hi there, really loving Monogame as I am able to do quite a lot already using the things I learnt in XNA. However I’m having trouble loading a .mp3 file. It gives an error when trying to load the content:

song1 = Content.Load(“songfilename”);

This gives error saying “songfilename is not a wave file”.
Interestingly, I tried converting from mp3 to wma and also ogg. There error changed to “not a content file”, even though the properties are set to content file and to copy always.

Even as a wave file , it just errors saying “Could not load songfilename asset as a non-content file”

Sorry to ask but does anyone know what I need to do to play mp3 or wma or ogg? thanks.

You cannot load an MP3 directly through the ContentManager. The ContentManager is designed to load XNB files, which for songs contains a reference to the song file itself.

If you want to load a MP3 file directly, use the Song.FromUri method.

Thanks for this. I had been converting to xnb with the attached wma file that is generated (using source files of mp3 and also .wav) and it just gives me the same errors. I clearly not understanding it properly its very frustrating. Thanks for your help tho, I will maybe try get my head around that FromUri method and/or just use the SoundEffect class

A trick I have used in the past is to take the xnb file generated by XNA and your mp3 of the same name. Use a hex editor to modify the xnb file and towards the end of the file you see the song filename. Change “.wma” to “.mp3” and save the xnb file.

1 Like

Thanks again. That’s exactly the kind of info I needed. I will look to do this now.

sadly i done all that and still errors. I have changed it to .mp3 in HxD editor. put mp3 file in Content folder with xnb file. It errors: “Not a wave file”.

So I try putting .wav file into Content folder and now new error:
An unhandled exception of type ‘System.DllNotFoundException’ occurred in MonoGame.Framework.dll

Additional information: Unable to load DLL ‘openal32.dll’: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

I am going to have to give up having a soundtrack for now. But still very much loving C# and Monogame for making coding games so fast and enjoyable.

BTW: I am using XNAFormatter to convert my audio files to xnb/wma. Is this known to cause issues?

DAMMMMMN! All I had to do was install openAL

Yes, as the additional information in the error said:

Additional information: Unable to load DLL 'openal32.dll': The specified module could not be found.

I’m currently porting one of my XNA game to iOS using Monogame.

When executing “myContentManager.Load(mySongName);”, an exception is raised: “Could not initialise an instance of the type ‘MonoTouch.AVFoundation.AVAudioPlayer’”.
Note that mySongName is an xnb (pointing to a wma file) which was generated from a mp3 file via the XNA ContentManager on Windows.

I followed the advices given in this thread: I patched xnb file (thanks to an hexEditor) to make it point to my mp3 source file (rather than wma generated file) and copied the mp3 file close to the xnb.

Unfortunately, the same exception is still raised.
(Note that I do not get the “Not a wave file” error, got by davejn82)

Can someone help me, please ?

I suspect you are using a nuget or release binary for MonoGame rather than source and you are targeting iOS 8.1 with the latest Xamarin.iOS Unified API. In which case the MonoTouch.AVFoundation.AVAudioPlayer probably moved to AVFoundation.AVAudioPlayer as that was part of the Unified changes. Try using the source or using the latest unstable releases.

Thanks dellis1972,
I’ll soon try your suggestions and I’ll inform you.

Thank you for this!
I have to add that what worked for me was to modify the .xnb file located in the build folder, which for me was
C:\Users\arthu\Documents\Game1\Game1\bin\DesktopGL\AnyCPU\Debug (because I was building in Debug mode).
Don’t confuse it with the .xnb file located in your Content folder (which for me was C:\Users\arthu\Documents\Game1\Game1\Content).

P.S: I didn’t have to modify the .xnb file with some hex editor, just opened it with Notepad++.
P.S2: This solution worked for me with a .wav file. I haven’t tried with other formats.

It’s weird that this wasn’t fixed as of 2019, though.
I’ve lost 1 hour searching around for this!