/* * $RCSfile: SoundManager.cs,v $ * Copyright (C) 2006 Rob Loach (http://robloach.net) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Reflection; using System.Runtime; using System.Runtime.InteropServices; using System.Resources; using System.IO; using System.Media; using System.Collections; using System.Collections.Generic; namespace ScreenCap { public class SoundManager { private static Dictionary m_Dictionary = new Dictionary(); /// /// Plays a wav file from the resource. /// /// The straight wav file name you would like to play. /// True when a wav file is successfully played. public static void PlayWav(string wav) { if (m_Dictionary.ContainsKey(wav)) { m_Dictionary[wav].Play(); } else { SoundPlayer player = new SoundPlayer(wav); player.LoadCompleted += new System.ComponentModel.AsyncCompletedEventHandler(player_LoadCompleted); player.LoadAsync(); m_Dictionary.Add(wav, player); } } private static void player_LoadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { ((SoundPlayer)sender).Play(); } } }