public void PlayMusic(string musicType, string name) { if (MusicDictionary.ContainsKey(musicType)) { if (MusicDictionary[musicType].ContainsKey(name)) { string newMusicLocation = MusicDictionary[musicType][name]; if (newMusicLocation != CurrentMusicLocation) { CurrentMusicLocation = newMusicLocation; if (CurrentMusic != null) { CurrentMusic.Dispose(); } CurrentMusic = new Music(CurrentMusicLocation) { Loop = true, Volume = 10 }; CurrentMusic.Play(); } } else { throw new ArgumentException("There is no music of this name", "musicType"); } } else { throw new ArgumentException("There is no music of this type", "musicType"); } }
public void StopMusic() { if (CurrentMusic != null) { CurrentMusic.Dispose(); } CurrentMusic = null; CurrentMusicLocation = null; CurrentMusicType = null; }
public void PlayRandomMusic(string musicType) { if (MusicDictionary.ContainsKey(musicType)) { if (musicType != CurrentMusicType) { CurrentMusicType = musicType; if (CurrentMusic != null) { CurrentMusic.Dispose(); } CurrentMusic = new Music(MusicDictionary[musicType].ElementAt(new Random().Next(0, MusicDictionary[musicType].Count)).Value) { Loop = true, Volume = 10 }; CurrentMusic.Play(); } } else { throw new ArgumentException("There is no music of this type", "musicType"); } }