Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Comment jouer 1 midi mis en fichier ressource ???

1 réponse
Avatar
le_troll
Bonjour,

J'ai mis en fichier ressource un midi, soit:
path CUSTOM 101

Mais ensuite, je prends quelle API pour jouer ce truc (il semble que
PlaySound ne soit faite que pour les Wav), et comment je fais (le code
svp)???

--
Merci, @+, bye, Joe
troll75 AROBASE iFrance POINT com
------------------------------------------
Ce message est plein de virus "certifiés"
Le_Troll, éleveur de Trolls depuis César, qui disait:
Avec une hache, celui qui tient le manche a toujours raison !
------------------------------------------

1 réponse

Avatar
ng
Salut,

Bah les même que pour un fichier normal...

Option Explicit

Private Declare Function mciSendString Lib "winmm.dll" Alias
"mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As
String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Public Function PlayResMIDI(intID As Integer) As String
Dim tblByMIDI() As Byte, k As Integer
tblByMIDI = LoadResData(intID, "MIDI")
k = FreeFile
PlayResMIDI = Environ$("tmp")
If Right$(PlayResMIDI, 1) <> "" Then PlayResMIDI = PlayResMIDI & ""
PlayResMIDI = PlayResMIDI & Int(Timer) & ".mid"
Open PlayResMIDI For Binary As #k
Put #k, , tblByMIDI
Close #k
Erase tblByMIDI
Call PlayMIDI(PlayResMIDI)
End Function

Public Sub StopResMIDI(strIDPath As String)
Call StopMIDI(strIDPath)
On Error Resume Next
Call Kill(strIDPath)
End Sub

Public Sub PlayMIDI(strPath As String)
Dim strAlias As String
strAlias = Mid$(strPath, InStrRev(strPath, "") + 1)
strAlias = Left$(strAlias, InStrRev(strAlias, ".") - 1)
Call mciSendString("OPEN " & strPath & " TYPE SEQUENCER ALIAS " & strAlias,
0&, 0, 0)
Call mciSendString("PLAY " & strAlias & " FROM 0", 0&, 0, 0)
Call mciSendString("CLOSE ANIMATION", 0&, 0, 0)
End Sub

Public Sub StopMIDI(strPath As String)
Dim strAlias As String
strAlias = Mid$(strPath, InStrRev(strPath, "") + 1)
strAlias = Left$(strAlias, InStrRev(strAlias, ".") - 1)
Call mciSendString("OPEN " & strPath & " TYPE SEQUENCER ALIAS " & strAlias,
0&, 0, 0)
Call mciSendString&("STOP " & strAlias, 0&, 0, 0)
Call mciSendString&("CLOSE ANIMATION", 0&, 0, 0)
End Sub



Private Sub Form_Load()
Dim strID As String
'//Ressource "MIDI" 101
strID = PlayResMIDI(101)

MsgBox "Cliquez pour arrêter"

Call StopResMIDI(strID)
End Sub

Il faut placer un fichier midi en ressource "MIDI" ID1 pour l'exemple

--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/
http://apisvb.europe.webmatrixhosting.net/



le_troll a écrit :

Bonjour,

J'ai mis en fichier ressource un midi, soit:
path CUSTOM 101

Mais ensuite, je prends quelle API pour jouer ce truc (il semble
que PlaySound ne soit faite que pour les Wav), et comment je fais (le
code svp)???