Lire un fichier son

Résolu
taoetc Messages postés 346 Date d'inscription lundi 8 septembre 2003 Statut Membre Dernière intervention 3 septembre 2007 - 3 juin 2005 à 11:39
Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 - 3 juin 2005 à 21:26
Bonjour, j'aimerais simplement lancer la lecture d'un fichier .wav.

J'ai bien vu une exemple, mais j'ai vu tout de suite l'importation d'un dll, et ca, grrrrr, j'aime pas.
N'y a t'il pas une classe dans c# qui permet de faire cela simplement, je demande pas la lune je pense.

J'ai aussi regarder un peu dans l'aide de vs.net, mais qu'est ce qu'elle peuit etre conne cette aide des fois ( enfin je trouve)

6 réponses

sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 37
3 juin 2005 à 11:48
de mémoire, je n'avais vu dans le FrameWork 1.1 de classes pour lire les fichiers musicaux. Par contre l'API PlaySound peut tu rendre service (http://www.pinvoke.net/default.aspx/winmm.PlaySound)

Sébastien FERRAND

Blog : http://blogs.developpeur.org/sebmafate
</FO< body>
3
cs_RMI Messages postés 305 Date d'inscription vendredi 18 juillet 2003 Statut Membre Dernière intervention 2 août 2010 2
3 juin 2005 à 14:59
La classe qui va bien...


using System;

using System.Runtime.InteropServices;

using Microsoft.Win32;





namespace Sound

{

/// <summary>

/// Permet de gerer des sons

/// </summary>

///



[Flags]

public enum SoundFlags : int

{

SND_SYNC = 0x0000, /* play synchronously (default) */

SND_ASYNC = 0x0001, /* play asynchronously */

SND_NODEFAULT = 0x0002, /* silence (!default) if sound not found */

SND_MEMORY = 0x0004, /* pszSound points to a memory file */

SND_LOOP = 0x0008, /* loop the sound until next sndPlaySound */

SND_NOSTOP = 0x0010, /* don't stop any currently playing sound */

SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */

SND_ALIAS = 0x00010000, /* name is a registry alias */

SND_ALIAS_ID = 0x00110000, /* alias is a predefined ID */

SND_FILENAME = 0x00020000, /* name is file name */

SND_RESOURCE = 0x00040004 /* name is resource name or atom */

}

//Sons systeme

public enum SoundEvent : int

{

DEFAUT=0,

ARRET_CRITIQUE=1,

ASTERISQUE=2,

DEMARRAGE_WINDOWS=3,

EXCLAMATION=4,

QUITTER_WINDOWS=5

}

public class Son

{

// PlaySound()

[DllImport("winmm.dll", SetLastError=true, CallingConvention=CallingConvention.Winapi)]

private static extern bool PlaySound( string pszSound,IntPtr hMod, SoundFlags sf );





/// <summary>

/// Lectures de sons

/// </summary>

///

//public static int Sonjouer(string _sFichierSon):this (_sFichierSon,SND_ASYNC);

public static int SonJouer(string _sFichierSon,SoundFlags _SoundFlags)

{

try

{

// play the sound from the selected filename

if (!PlaySound( _sFichierSon, IntPtr.Zero,


SoundFlags.SND_FILENAME |
_SoundFlags ))

return -1;



//MessageBox.Show(this,"Impossible de jouer le son "+_sFichierSon);

}

catch

{

return Marshal.GetLastWin32Error();

// if (err != 0)

//
MessageBox.Show( this,"Error " +
err.ToString(),"PlaySound()
failed",MessageBoxButtons.OK,MessageBoxIcon.Error );

}

return 0;

}







public static int SonJouer(SoundEvent _SoundEvent, SoundFlags _SoundFlags)

{

string sRootKey = "AppEvents\\Schemes\\Apps\\.Default";

switch (_SoundEvent)

{


case SoundEvent.DEFAUT:
sRootKey += "\\.default";break;


case
SoundEvent.ARRET_CRITIQUE: sRootKey +=
"\\SystemHand";break;


case SoundEvent.ASTERISQUE:
sRootKey += "\\SystemAsterisk";break;


case
SoundEvent.DEMARRAGE_WINDOWS: sRootKey +=
"\\SystemStart";break;


case SoundEvent.EXCLAMATION:
sRootKey += "\\SystemExclamation";break;


case
SoundEvent.QUITTER_WINDOWS: sRootKey +=
"\\SystemExit";break;

default: return -1;

}


RegistryKey rkKey =
Registry.CurrentUser.OpenSubKey(sRootKey+ "\\.Current", false);

string sSon;

if (rkKey != null)

{

sSon=rkKey.GetValue(null).ToString();

if (sSon.Length > 0)

{

rkKey.Close();


return
SonJouer(sSon,_SoundFlags);

}

else return -1;

}

else return -1;







}

public Son()

{

//

// TODO : ajoutez ici la logique du constructeur

//

}

}

}


Théo
3
MorpionMx Messages postés 3466 Date d'inscription lundi 16 octobre 2000 Statut Membre Dernière intervention 30 octobre 2008 57
3 juin 2005 à 13:41
Je confirme les propos de sebmafate.

Sinon, tu peux toujours te servir aussi de DirectX

Mx
0
taoetc Messages postés 346 Date d'inscription lundi 8 septembre 2003 Statut Membre Dernière intervention 3 septembre 2007 3
3 juin 2005 à 15:04
Au fait, ce que je veux, c'est au maximum utilisé le framework , pour le déployement, c'est quand meme bien mieux, donc, directX, je pensequ'il y a un peu trop de version pour qu'un déployement ce passe bien, bon, la dll winmm.dll, je voulais l'éviter, j'ai pas le choix, tant pis

merci
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 37
3 juin 2005 à 15:08
winmm.dll est standard... tu la retourves sur tous les windows.

Sébastien FERRAND

Blog : http://blogs.developpeur.org/sebmafate
</FO< body>
0
Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
3 juin 2005 à 21:26
Eh! Sebmafate, je le connaissais pas moi ce site, pinvoke.net.... Pfff bon bha maintenant je le connais : )

Taoetc, tu peux aussi utiliser la lib FMOD, d'apres les specialistes c'est la meilleure, elle fonctionne sur tout le systemes possibles mais elle est ecrite en C.
0
Rejoignez-nous