Dossiers
This commit is contained in:
57
JeuHoyEtudiants/JeuHoy_WPF_Natif/Presenter/JouerMp3.cs
Normal file
57
JeuHoyEtudiants/JeuHoy_WPF_Natif/Presenter/JouerMp3.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace JeuHoy_WPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Auteur: Hugo St-Louis
|
||||
/// Description: Permet de faire jouer un mp3
|
||||
/// Date: 26/04/2014
|
||||
/// </summary>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Ferme et stop un mp3 qui joue
|
||||
/// </summary>
|
||||
public void Close()
|
||||
{
|
||||
_command = "close MediaFile";
|
||||
mciSendString(_command, null, 0, IntPtr.Zero);
|
||||
isOpen = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ouvre un mp3
|
||||
/// </summary>
|
||||
/// <param name="sFileName"></param>
|
||||
public void Open(string sFileName)
|
||||
{
|
||||
_command = "open \"" + sFileName + "\" type mpegvideo alias MediaFile";
|
||||
mciSendString(_command, null, 0, IntPtr.Zero);
|
||||
isOpen = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fait jouer un mp3
|
||||
/// </summary>
|
||||
/// <param name="loop">Détermine si le mp3 doit jouer en boucle.</param>
|
||||
public void Play(bool loop)
|
||||
{
|
||||
if (isOpen)
|
||||
{
|
||||
_command = "play MediaFile";
|
||||
if (loop)
|
||||
_command += " REPEAT";
|
||||
mciSendString(_command, null, 0, IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
35
JeuHoyEtudiants/JeuHoy_WPF_Natif/Presenter/JouerSon.cs
Normal file
35
JeuHoyEtudiants/JeuHoy_WPF_Natif/Presenter/JouerSon.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.ComponentModel;
|
||||
using System.Media;
|
||||
|
||||
namespace JeuHoy_WPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Auteur: Hugo St-Louis
|
||||
/// Description: Permet de faire jouer un son asynchrone.
|
||||
/// Date: 26/04/2014
|
||||
/// </summary>
|
||||
public class JouerSon
|
||||
{
|
||||
/// <summary>
|
||||
/// Permet de faire charger un son et de le faire jouer de manière asynchrone.
|
||||
/// </summary>
|
||||
/// <param name="FichierSon"></param>
|
||||
public void JouerSonAsync(string FichierSon)
|
||||
{
|
||||
SoundPlayer wavPlayer = new SoundPlayer();
|
||||
wavPlayer.SoundLocation = FichierSon;
|
||||
wavPlayer.LoadCompleted += new AsyncCompletedEventHandler(wavPlayer_LoadCompleted);
|
||||
wavPlayer.LoadAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fait jouer le son.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void wavPlayer_LoadCompleted(object sender, AsyncCompletedEventArgs e)
|
||||
{
|
||||
((System.Media.SoundPlayer)sender).Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user