Jouer mp3 sur Excel
Bonjour le forum!
j'ai trouver ce code sur le net qui fonction très bien, j'ai pu l'adapter a mon classeur
Sub PlayOn()
Song = "I:\xxxx\yyyy.mp3"
Call PlaySong(True)
End Sub
Private Sub PlaySong(Play As Boolean, Optional Reprise As Long = 0)
On Error Resume Next
Call mciSendString("Stop MPFE", 0&, 0, 0)
Call mciSendString("Close MPFE", 0&, 0, 0)
If Not Play Then Exit Sub
If Song = "" Or Dir(Song) = "" Then Exit Sub
Song = GetShortPath(Song)
Call mciSendString("Open " & Song & " Alias MPFE", 0&, 0, 0)
Call mciSendString("play MPFE from " & Reprise, 0&, 0, 0)
End Sub
mais je n'arrive pas a trouver comment lui faire jouer plusieurs morceaux, exemple 4 morceau de façon aléatoire
si quelqu'un a une idée et pouvait m'en faire profiter je l'en remercie d'avance
Bonjour
Avec ce code associé à un bouton, la fonction Aléa détermine le morceau qui sera joué.
Essaie de l'adapter à tes mp3
Declare Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpzSoundName As String, ByVal uFlags As Long) As Long
Sub jouer()
Dim i As Byte
i = Int(Rnd * 4) + 1
If i = 1 Then
Call sndPlaySound32("D:\Mes documents\Wav\wmpaud1.wav", 0) '"I:\xxxx\yyyy.mp3"
ElseIf i = 2 Then
Call sndPlaySound32("D:\Mes documents\Wav\wmpaud2.wav", 0)
ElseIf i = 3 Then
Call sndPlaySound32("D:\Mes documents\Wav\wmpaud3.wav", 0)
ElseIf i = 4 Then
Call sndPlaySound32("D:\Mes documents\Wav\wmpaud4.wav", 0)
End If
End SubCordialement
Merci Amadéus
je vais essayer d'adapter ton code au mien, et je te tiens au courant du résultat,
Encore merci pour ton aide et bonne journée
Bonsoir Amadéus
voici le code complet "il pourra servir à quelqu'un" avec tes modifications, et cela fonctionne très bien encore merci pour tout.
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
Private Declare Function GetShortPathName Lib "kernel32" Alias _
"GetShortPathNameA" (ByVal lpszLongPath As String _
, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
Private Song As String
_____________________________________________________________________________________________________________
Sub PlayOn()
Dim i As Byte
Randomize
i = Int(Rnd * 4) + 1
If i = 1 Then
Song = "I:\Anglais\Yannick Noah - Angela.mp3"
Call PlaySong(True)
ElseIf i = 2 Then
Song = "I:\Anglais\Zaz - Eblouie Par La Nuit.mp3"
Call PlaySong(True)
ElseIf i = 3 Then
Song = "I:\Anglais\René La Taupe - Mignon Mignon.mp3"
Call PlaySong(True)
ElseIf i = 4 Then
Song = "I:\Anglais\Bruno Mars - The Lazy Song.mp3"
Call PlaySong(True)
End If
End Sub
______________________________________________________________________________________________________________
Sub PlayOff()
Call PlaySong(False)
End Sub
_______________________________________________________________________________________________________________
Sub PlayPauseReprise()
Dim msg As String * 255
Static iPos As Long
Static nb As Integer
If nb Then
PlaySong True, iPos
Else
mciSendString "status MPFE position", msg, 255, 0
iPos = Str(msg)
mciSendString "Pause MPFE", 0, 0, 0
End If
nb = Not nb
End Sub
__________________________________________________________________________________________________________________________
Private Sub PlaySong(Play As Boolean, Optional Reprise As Long = 0)
On Error Resume Next
Call mciSendString("Stop MPFE", 0&, 0, 0)
Call mciSendString("Close MPFE", 0&, 0, 0)
If Not Play Then Exit Sub
If Song = "" Or Dir(Song) = "" Then Exit Sub
Song = GetShortPath(Song)
Call mciSendString("Open " & Song & " Alias MPFE", 0&, 0, 0)
Call mciSendString("play MPFE from " & Reprise, 0&, 0, 0)
End Sub
_________________________________________________________________________________________________________________________
Private Function GetShortPath(strFileName As String) As String
Dim lngRes As Long, strPath As String
strPath = String(165, 0)
lngRes = GetShortPathName(strFileName, strPath, 164)
GetShortPath = Left(strPath, lngRes)
End Function