problem with audio playback in WP8.1

I’m trying to add audio playback to my Monogame game in Windows Phone 8.1.
I experienced a problem that I can replicate evry easily with a basic prototype:

  • compile WAV file to XNB from a VS2012 Windows Phone project
  • add a SoundEffect object to Game1.cs
  • initialize SoundEffect in LoadContent from XNB file
  • call SoundEffect.Play()

When doing so, I receive following unhandled exception at runtime (SharpDX.SharpDXException) in SharpDX.DLL:
HRESULT: [0x88960001], Module: [SharpDX.XAudio2], ApiCode: [XAUDIO2_E_INVALID_CALL/InvalidCall], Message: Unknown

I tried to create a SoundEffectInstance and play that instead of SoundEffect but the error is the same.
I also tried to recompile XNB file to switch between XNA and Monogame processor but no difference.

I made different tests by running the same code on following project types :

  • Windows Phone 8 Monogame project template from latest stable Monogame intaller
  • Windows Phone 8 Monogame project template from latest unstable Monogame intaller
  • Windows Phone 8 standard Visual Studio template + latest stable nuget Monogame package
  • Windows Phone 8 standard Visual Studio template + latest unstable nuget Monogame package
  • Windows Store Monogame project template from latest stable Monogame installer
  • Windows Store Monogame project template from latest unstable Monogame installer

All of the above present the same exception.
The only project where exactly the same code runs succesfully is a Monogame OpenGL Windows Desktop game.

I have tried everyhting but I am not able to make this work.
In the past I used the same code in XNA and I had no problems in playing audio files.
I also see that Monogame samples use the same classes and methods so I don’t think I’m doing something wrong with my code.

Does anyone have any hint?


Everything is fine here. Maybe your SharpDX is out of date?

Hi Nezz and thanks for your reply.
I’m not sure what you mean, as I would expect that MonoGame installer and nuget packages would automatically include the correct required version of SharpDX.
Anyway I tried to include latest release of SharpDX through nuget package in my project but I still have the same problem.
Ot maybe you meant something different?

Ok so I made further tests by running the Platformer2D sample in the same environment, and music/sound worked just fine.
Then i tried to grab sound XNBs from Platformer2D and they did work in my project too.
Turns out it was a problem with my content builder project, although I can’t figure out where the problem is as all other XNB (texture, spritefont) used to work correctly.
Anyways i am now using the new MonoGame Pipeline utility and everything seems to be working fine with the resulting XNBs.

It might be the compression that you’ve used. Glad to hear that the pipeline utility solved the problems for you :smile:

This happens when using sound assets (.XNB) generated by XNA content pipeline.
Sometimes XNA produce sample rates greater than 48000, I have seen values between 48000 & 48152.

Changing this line to accept values up to 48152 solve the problem and everything seems to work fine. This line was introduced recently, so I wonted if it’s save to revert it or increase the top limit like I did just to support old .xnb sound files.

Thanks for your explanation nkast! That totally makes sense as my content project was initially created as a XNA content project through VS Express 2012 for Windows Phone. And this also explains why recompiling the same original WAV file with Monogame Pipeline tool gives me a valid XNB. I think I will just go on with this tool now, but your information could be very helpful indeed when dealing with WAV files.