示例#1
0
		private void _copyFrom(EOSoundManager other)
		{
			//shallow copy is intended
			m_sounds = other.m_sounds;
			m_guitarSounds = other.m_guitarSounds;
			m_harpSounds = other.m_harpSounds;
			m_music = other.m_music;
		}
示例#2
0
		public EOSoundManager()
		{
			lock (_construction_locker_)
			{
				if (inst != null)
				{
					_copyFrom(inst);
					return;
				}

				string[] soundFiles = Directory.GetFiles(SFX_DIR, "*.wav");
				Array.Sort(soundFiles);

				string[] musicFiles = Directory.GetFiles(MFX_DIR, "*.mid");
				Array.Sort(musicFiles);

				m_sounds = new List<SoundInfo>(81);
				m_guitarSounds = new List<SoundInfo>(36);
				m_harpSounds = new List<SoundInfo>(36);
				m_music = new List<Uri>(musicFiles.Length);

				foreach (string sfx in soundFiles)
				{
					_correctTheFileLength(sfx);

					using (FileStream fs = new FileStream(sfx, FileMode.Open, FileAccess.Read, FileShare.Read))
					{
						//Note: this MAY throw InvalidOperationException if the file is invalid. However, _correctTheFileLength fixes
						//	this for the original sfx files.
						SoundEffect nextEffect = SoundEffect.FromStream(fs);

						if (sfx.ToLower().Contains("gui"))
							m_guitarSounds.Add(nextEffect == null ? null : new SoundInfo(nextEffect));
						else if (sfx.ToLower().Contains("har"))
							m_harpSounds.Add(nextEffect == null ? null : new SoundInfo(nextEffect));
						else
							m_sounds.Add(nextEffect == null ? null : new SoundInfo(nextEffect));
					}
				}

				m_songPlayer = new System.Windows.Media.MediaPlayer();
				m_dispatcher = Dispatcher.CurrentDispatcher;
				m_songPlayer.MediaEnded += (o, e) => m_songPlayer.Position = new TimeSpan(0);

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

				inst = this;
			}
		}