Is .wav the only format we can use to play music ?

I’m pretty disappointed right now. I’m trying to export my project from XNA to Monogame but audio format is a real problem. I’ve the following exception send by the AudioLoader when trying to load .wma file in a Song instance :

System.NotSupportedException("Specified stream is not a wave file.")

I’ve read a lot of post but I didn’t find a clear answer about this fact : is it possible to load an other song format than .wav ? I’ve read the source code and comments indicate it isn’t possible.

// decide which data type is this // for now we'll only support wave files audioData = LoadWave(reader, out format, out size, out frequency);

Is it something you work on ? Does it exist an other method ?

Wav file are good for sound effect but clearly not for big music files. So I’m very surprise to not see alternative in audio formats, especially because it was possible with XNA.

I’m using .mp3 for my music on iOS and Android, should also work fine on Windows Phone. I’m loading the file into a Song instance like this:

sndMusicInGame = content.Load(“music-in-game”); (in Content folder)

And playing it using the Microsoft.Xna.Framework.Media.MediaPlayer static class like this:

MediaPlayer.IsRepeating = true;
MediaPlayer.Volume = 1.0f;
MediaPlayer.Play(sndMusicInGame);

Hope this helps,
Ronny.

I do the same and I tested with “mp3” & “wma”. Apparently “.wav” is the only option on Windows because Song use a SoundEffect instance on this platform :

 private void PlatformInitialize(string fileName)
{
#if MONOMAC || (WINDOWS && OPENGL) || WEB
using (var s = File.OpenRead(_name))
{
var soundEffect = SoundEffect.FromStream(s);
_sound = soundEffect.CreateInstance();
}
#endif
}

I’ll be glad to have some explanations about this fact by a MonoGame developer. Why is it possible on other platform but not on Windows ? If an implementation is possible, can I count on it in a near future ?

The stack trace show it clearly too (partially in French, sorry) :

L’exception System.NotSupportedException n’a pas été gérée
_HResult=-2146233067
_message=Specified stream is not a wave file.
HResult=-2146233067
IsTransient=false
Message=Specified stream is not a wave file.
Source=MonoGame.Framework
StackTrace:
à Microsoft.Xna.Framework.Audio.AudioLoader.LoadWave(BinaryReader reader, ALFormat& format, Int32& size, Int32& frequency)
à Microsoft.Xna.Framework.Audio.AudioLoader.Load(Stream data, ALFormat& format, Int32& size, Int32& frequency)
à Microsoft.Xna.Framework.Audio.SoundEffect.LoadAudioStream(Stream s, Single volume, Boolean looping)
à Microsoft.Xna.Framework.Audio.SoundEffect…ctor(String fileName)
à Microsoft.Xna.Framework.Media.Song…ctor(String fileName)
à Microsoft.Xna.Framework.Content.ContentManager.ReadRawAsset[T](String assetName, String originalAssetName)
à Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject)
à Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName)

I’d be glad to have some advices from the community or explanations from developers. It’s a problem that paralyze us and question us about the changement of technology to MonoGame.

My guess is that it needs an external library and nobody really cared enough to implement it (WinGL is still a pretty young MonoGame platform). You can use DirectX version of MonoGame if you want music playback.

Okay, I discovered that I used the OpenGl version. ^^"
I don’t know why but it was the default version when I used the binairies Nuget package. And nothing indicate that it was the OpenGL version. I will try with DirectX.

It’s me again.

Ok so I replace my MonoGame OpenGL NuGet packages by the stable MonoGame DirectX v3.2 but I have always exception with my Song load.

I have a ContentLoadException exception :

L'exception Microsoft.Xna.Framework.Content.ContentLoadException n'a pas été gérée
  _HResult=-2146233088
  _message=Could not load Music\Inner World.xnb asset!
  HResult=-2146233088
  IsTransient=false
  Message=Could not load Music\Inner World.xnb asset!
  Source=MonoGame.Framework
  StackTrace:
       à Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject)
       à Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName)

I used the last Pipeline.exe for compile my content. My music file are in WMA. The two files generated (.xnb & .wma) are in the Content/Music folder of my game project.

I tested with other formats (mp3, wav) but I had always the same exception.

Always have the same errors. I really need some advices.
Could the errors come from the use of the last Pipeline.exe with stable Monogame v3.2 ?

I have update my version of MonoGame with the generated installer of the last build. It solve some of my bugs but not the load of Songs. Always the same exception. I’ll try with other formats.

I'm a little desperate. Always the same ContentLoadException and no solutions.

As reminder, here's my exception details : 

L'exception Microsoft.Xna.Framework.Content.ContentLoadException n'a pas été gérée
  _HResult=-2146233088
  _message=Could not load Music\Inner World.xnb asset!
  HResult=-2146233088
  IsTransient=false
  Message=Could not load Music\Inner World.xnb asset!
  Source=MonoGame.Framework
  StackTrace:
       à Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject)
       à Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName) 

I used the last build installer with the DirectX base. I compile my content with the new Pipeline executable. My Song are in WMA (I also test with MP3 & WAV) and are compile with the importer “Wma Importer - MonoGame” and the processor “Song - MonoGame”.

The exception take place at this line :

_musics.Add(asset.Substring(asset.LastIndexOf('\\') + 1), content.Load<Song>(path));

where path = “Music\Inner World.xnb”

If someone have success in load music as Song, I’ll be glad to see his code.

Sorry for the round-about solution, but I do know that the FlatRedBall game engine is able to load and play songs on Windows 8 RT apps. Maybe the source there will be helpful?

http://documentation.flatredball.com/frb/docs/index.php?title=Contributors:Setup:Getting_Source

I’d rather like not to use 3rd party solution to load and play music in my game… It should be a shame since it’s implemented in MonoGame.

I’m aware that MonoGame have a lot of work in progress but nothing said that Song loading didn’t work for Windows. I’ll be glad to have feedback from someone who developed for Windows (and not only W8) with MonoGame.

I was not necessarily suggesting you use a 3rd party solution (although FRB is a good solution if you do want one). Instead, I’m just saying you can get a project set up to load music, then see what it’s doing, then rip the code out and put it in your own project.

Is there more to that exception? Seems like maybe you cut off some information there. In particular the inner exception is what will tell you more specifically what the issue is.

I haven’t done any Windows Phone dev so this may be a silly question but do you have to use an .xnb file for your music? I guess you do because the Song class is forcing you to use .wav instead of .mp3. I’m assuming you’ve tried with different files, couldn’t be something as simple as the space in the filename?

First i assume what you are asking is: Do you have to use the content pipeline?

Let’s start with a clarification… music run thru the content pipeline isn’t really an XNB file. There is an XNB used to store information like the duration, but the actual music data is stored in a companion file that is usually a format you know… mp3, wma, ogg, etc.

So do you need to use the content pipeline to process music? No.

MonoGame for a long time has circumvented the content pipeline and exposed some extra functionality to allow non-pipeline processed content to be loaded. This is mostly a legacy feature for Mac/Linux developers that could not run MS XNA to process content. That said… these features will be removed in the next year.

MonoGame has nearly completely replicated the content pipeline from XNA. This allows us to finally processes content on non-Windows desktop machines. There will be no good excuse to not process your content via the content pipeline in the future.

Second question… Why should we use the content pipeline?

Most game art/content formats are just optimized for passive viewing on PCs or for editing the content. They are not optimized for real time game rendering. The content pipeline is there to transform these formats into the correct optimized format for your target platform. So instead of you using suboptimal content formats or having to manually manage several versions of your files optimized to each platform… you simply use the content pipeline and it takes care of this for you.

The content pipeline was one of the thing that made XNA awesome and it’s always as awesome with MonoGame. :wink:

I checked : the inner exception is null. That’s why I’m very hopeless about this exception : I have no idea of what going on.

Always the same bug. It’s really embarrasing.

I’ll be glad if someone can give me certainties about this Is it still in development ? If not, I think there is at least one person who develop for Windows success to play music. What I want to know is how he do.