mono/MonoGame — pull request #1509 by SimonPStevens (2013-03-06 18:56:16+00:00)
Title: Fixed exception when loading a song before the MediaManager is initialised, and added called to Shutdown() on game exit.

I was getting a SharpDXException (see below) when calling `Content.Load(...)`.

(WindowsDX)

The cause was that the `MediaManager.StartUp(...)` call was only being done in the static constructor of the MediaPlayer, this meant if the Song was loaded before the MediaPlayer was used an exception was thrown.

I've added a MediaManagerState class to control the startup to ensure it only gets started once, and I've also added a shutdown call to the Game class.

Full exception details:

SharpDX.SharpDXException was unhandled
HResult=-1072873851
Message=HRESULT: [0xC00D3E85], Module: [Unknown], ApiCode: [Unknown/Unknown], Message: Unknown
Source=SharpDX
StackTrace:
at SharpDX.Result.CheckError()
at SharpDX.MediaFoundation.SourceResolver.CreateObjectFromURL(String wszURLRef, Int32 dwFlags, ComObject propsRef, ObjectType& objectTypeRef, ComObject& objectOut)
at Microsoft.Xna.Framework.Media.Song.GetTopology() in c:\Development\MonoGame\MonoGame.Framework\Media\Song.cs:line 197
at Microsoft.Xna.Framework.Media.Song..ctor(String fileName) in c:\Development\MonoGame\MonoGame.Framework\Media\Song.cs:line 90
at Microsoft.Xna.Framework.Media.Song..ctor(String fileName, Int32 durationMS) in c:\Development\MonoGame\MonoGame.Framework\Media\Song.cs:line 73
at Microsoft.Xna.Framework.Content.SongReader.Read(ContentReader input, Song existingInstance) in c:\Development\MonoGame\MonoGame.Framework\Content\ContentReaders\SongReader.cs:line 93
at Microsoft.Xna.Framework.Content.ContentTypeReader`1.Read(ContentReader input, Object existingInstance) in c:\Development\MonoGame\MonoGame.Framework\Content\ContentTypeReader.cs:line 185
at Microsoft.Xna.Framework.Content.ContentReader.ReadObject[T]() in c:\Development\MonoGame\MonoGame.Framework\Content\ContentReader.cs:line 217
at Microsoft.Xna.Framework.Content.ContentReader.ReadAsset[T]() in c:\Development\MonoGame\MonoGame.Framework\Content\ContentReader.cs:line 100
at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject) in c:\Development\MonoGame\MonoGame.Framework\Content\ContentManager.cs:line 289
at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName) in c:\Development\MonoGame\MonoGame.Framework\Content\ContentManager.cs:line 212
at TestApp.TestGame.Initialize() in c:\Development\TestApp\TestGame.cs:line 106
at Microsoft.Xna.Framework.Game.DoInitialize() in c:\Development\MonoGame\MonoGame.Framework\Game.cs:line 691
at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior) in c:\Development\MonoGame\MonoGame.Framework\Game.cs:line 415
at Microsoft.Xna.Framework.Game.Run() in c:\Development\MonoGame\MonoGame.Framework\Game.cs:line 405
at TestApp.Program.Main(String[] args) in c:\Development\TestApp\Program.cs:line 17
InnerException: