Example #1
0
		public SoundManager()
		{
			lock (_construction_locker_)
			{
				if (_singletonInstance != null)
				{
					CopyFromInstance();
					return;
				}

				var soundFiles = Directory.GetFiles(SFX_DIR, "*.wav");
				Array.Sort(soundFiles);

				var musicFiles = Directory.GetFiles(MFX_DIR, "*.mid");
				Array.Sort(musicFiles);

				_soundEffects = new List<SoundInfo>(81);
				_guitarSounds = new List<SoundInfo>(36);
				_harpSounds = new List<SoundInfo>(36);
				_musicFiles = new List<Uri>(musicFiles.Length);

				foreach (var sfx in soundFiles)
				{
					using (var sfxStream = WAVFileValidator.GetStreamWithCorrectLengthHeader(sfx))
					{
						//Note: this MAY throw InvalidOperationException if the file is invalid. However, WAVFileValidator fixes
						//	this for the original sfx files.
						SoundEffect nextEffect = SoundEffect.FromStream(sfxStream);

						if (sfx.ToLower().Contains("gui"))
							_guitarSounds.Add(nextEffect == null ? null : new SoundInfo(nextEffect));
						else if (sfx.ToLower().Contains("har"))
							_harpSounds.Add(nextEffect == null ? null : new SoundInfo(nextEffect));
						else
							_soundEffects.Add(nextEffect == null ? null : new SoundInfo(nextEffect));
					}
				}

				_musicPlayer = new MediaPlayer();
				_musicPlayer.MediaEnded += (o, e) => _musicPlayer.Position = new TimeSpan(0);

				foreach (string mfx in musicFiles)
					_musicFiles.Add(new Uri(mfx, UriKind.Relative));

				_dispatcher = Dispatcher.CurrentDispatcher;

				_singletonInstance = this;
			}
		}
		public EffectSoundManager(SoundManager soundManager)
		{
			_soundManager = soundManager;
		}
Example #3
0
		private bool InitializeSoundManager()
		{
			try
			{
				SoundManager = new SoundManager();
			}
			catch (Exception ex)
			{
				MessageBox.Show(
					string.Format("There was an error (type: {2}) initializing the sound manager: {0}\n\nCall Stack:\n {1}", ex.Message,
						ex.StackTrace, ex.GetType()), "Sound Manager Error");
				Exit();
				return false;
			}

			if (World.Instance.MusicEnabled)
				SoundManager.PlayBackgroundMusic(1); //mfx001 == main menu theme
			return true;
		}