Ejemplo n.º 1
0
 /// <summary>
 /// Toca um som desta coleção
 /// </summary>
 /// <param name="soundName">Nome (alias) do audio a ser tocado</param>
 public void Play(string soundName, bool loop = false)
 {
     if (sounds.ContainsKey(soundName))
     {
         MciPlayer player = sounds[soundName];
         player.Play(loop);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Para de tocar um som desta coleção
 /// </summary>
 /// <param name="soundName">Nome (alias) do audio que está tocando</param>
 public void Stop(string soundName)
 {
     if (sounds.ContainsKey(soundName))
     {
         MciPlayer player = sounds[soundName];
         player.Stop();
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Remove um audio desta coleção
 /// </summary>
 /// <param name="soundName">Nome (alias) do audio a ser removido</param>
 public void Remove(string soundName)
 {
     if (sounds.ContainsKey(soundName))
     {
         MciPlayer player = sounds[soundName];
         sounds.Remove(soundName);
         player.Close();
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Adiciona um novo audio a coleção, carregando-o para que ele esteja pronto pra tocar
        /// </summary>
        /// <param name="soundName">Nome (alias) do audio</param>
        /// <param name="resourceName">Caminho do recurso associado ao audio</param>
        public void Add(string soundName, string resourceName)
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\" + System.AppDomain.CurrentDomain.FriendlyName + "\\Resources\\Sounds";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string sound_path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\" + System.AppDomain.CurrentDomain.FriendlyName + "\\Resources\\Sounds\\" + resourceName;

            if (!File.Exists(sound_path))
            {
                Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Bomberman.Resources.Sounds." + resourceName);
                byte[] buffer = new byte[stream.Length];
                stream.Read(buffer, 0, buffer.Length);
                File.WriteAllBytes(sound_path, buffer);
            }

            MciPlayer player = new MciPlayer(sound_path, soundName);

            sounds.Add(soundName, player);
        }