OVH Cloud OVH Cloud

Executer un son !

2 réponses
Avatar
Michel
Plutot EXECUTER un son ! je voulais dire...

Merci encore !

2 réponses

Avatar
Aski
Hello Michel,

Tu as savamment écrit :

Plutot EXECUTER un son ! je voulais dire...

Merci encore !



Utilise l'API "sndPlaySoundA" (détail dans les CD d'aide)
Avatar
Jacques93
Bonjour Michel,
Michel a écrit :
Plutot EXECUTER un son ! je voulais dire...

Merci encore !





Suivant que ton son est dans un fichier, ou en mémoire(.res), tu peux
utiliser :

Option Explicit

Private Const SND_ASYNC = &H1
Private Const SND_FILENAME = &H20000
Private Const SND_LOOP = &H8
Private Const SND_MEMORY = &H4
Private Const SND_NODEFAULT = &H2
Private Const SND_SYNC = &H0

Private Declare Function sndPlaySound Lib "winmm.dll" Alias
"sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
Private Declare Function PlaySoundA Lib "winmm.dll" (ByVal lpszName As
String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Dim m() As Byte

Public Sub PlaySoundInMemory(ResName, Optional Wait As Boolean = False)
Dim resErr As Long, Flags As Long

On Error Resume Next
Err.Clear
m = LoadResData(ResName, "WAVE")
resErr = Err.Number
If resErr = 0 Then
Flags = SND_NODEFAULT Or SND_MEMORY Or SND_SYNC
If Wait = False Then Flags = Flags Or SND_ASYNC
sndPlaySound m(0), Flags
End If
End Sub


Private Sub PlaySoundAsFile(fName As String, Optional Wait As Boolean =
False)
Dim Flags As Long

Flags = SND_NODEFAULT Or SND_FILENAME Or SND_SYNC
If Wait = False Then Flags = Flags Or SND_ASYNC
PlaySoundA fName, 0&, Flags
End Sub

Private Sub Command1_Click()
PlaySoundAsFile "C:MonSon.wav"
PlaySoundInMemory "MONSON"
End Sub

--
Cordialement,

Jacques.