internal SoundEffect(ContentManager content, string assetName) { Stream s = content.GetAssetStream(assetName, ".mp3"); if(s == null) { s = content.GetAssetStream(assetName, ".wma"); } if(s == null) { s = content.GetAssetStream(assetName, ".wav"); if(s != null) { isWav = true; } } if(s == null) throw new ContentLoadException("Could not load audio asset: " + assetName); soundBuffer = new byte[s.Length]; s.Read(soundBuffer, 0, soundBuffer.Length); s.Close(); device = ((IGraphicsDeviceService)content.ServiceProvider.GetService(typeof(IGraphicsDeviceService))).GraphicsDevice; }
public SoundEffect(ContentManager content, string assetName) { _assetName = assetName; if (soundBuffers.ContainsKey(assetName) == true) { _isWav = false; } else if (wavSoundBuffers.ContainsKey(assetName) == true) { _isWav = true; } else { Stream s = content.GetAssetStream(_assetName, ".mp3"); if (s == null) { s = content.GetAssetStream(_assetName, ".wma"); } if (s == null) { s = content.GetAssetStream(_assetName, ".wav"); if (s != null) { _isWav = true; } } if (s == null) throw new ContentLoadException("Could not load audio asset: " + assetName + "\r\nSilverSprite only supports MP3, WAV, and WMA audio assets."); byte[] b = new byte[s.Length]; s.Read(b, 0, b.Length); s.Close(); if (_isWav) { wavSoundBuffers.Add(assetName, b); } else { soundBuffers.Add(assetName, b); } } _graphics = ((IGraphicsDeviceService)content.ServiceProvider.GetService(typeof(IGraphicsDeviceService))).GraphicsDevice; }