using System; using System.Text; using System.Runtime.InteropServices; namespace JeuHoy_WPF { /// /// Auteur: Hugo St-Louis /// Description: Permet de faire jouer un mp3 /// Date: 26/04/2014 /// public class JouerMp3 { private string _command; private bool isOpen = false; [DllImport("winmm.dll")] private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback); /// /// Ferme et stop un mp3 qui joue /// public void Close() { _command = "close MediaFile"; mciSendString(_command, null, 0, IntPtr.Zero); isOpen = false; } /// /// Ouvre un mp3 /// /// public void Open(string sFileName) { _command = "open \"" + sFileName + "\" type mpegvideo alias MediaFile"; mciSendString(_command, null, 0, IntPtr.Zero); isOpen = true; } /// /// Fait jouer un mp3 /// /// Détermine si le mp3 doit jouer en boucle. public void Play(bool loop) { if (isOpen) { _command = "play MediaFile"; if (loop) _command += " REPEAT"; mciSendString(_command, null, 0, IntPtr.Zero); } } } }