MP3 via VBA abspielen unter 64bit geht nicht mehr
22.02.2017 20:27:51
Olli
Verzweifel gerade und hoffe auf eure Hilfe.
Ich lasse per VBA eine MP3 Datei abspielen. Das hat mit meinem alten Rechner Win10/32bit auch problemlos funktioniert.
Jetzt habe ich einen neuen Rechner mit Win10 /64bit /Office 2016 /32bit und da funktioniert es nicht. Die Codes laufen ohne Probleme, aber es kommt kein Sound raus.
Hat jemand eine Ahung, wo mein Fehler ist? Kann es an der 64bit-Windowsversion liegen?
Würde mich riesig freuen, wenn mir wer helfen könnte.
Viele Grüße
Olli
Nachfolgend der Code:
'Modul MP3-Play and Stop via API
Option Explicit
'zunächst die benötigte API-Deklaration
Private Declare Function mciSendString Lib "winmm.dll" _
Alias "mciSendStringA" (ByVal lpszCommand As String, _
ByVal lpszReturnString As String, _
ByVal cchReturnLength 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 cchBuffer As Long) As Long
'MP3-Datei abspielen
Public Function MP3_Play(ByVal sFile As String, _
ByVal sAlias As String) As Boolean
Dim bResult As Boolean
Dim sBuffer As String
Dim lResult As Long
sBuffer = Space$(255)
lResult = GetShortPathName(sFile, sBuffer, Len(sBuffer))
If lResult 0 Then
sFile = Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1)
' MCI öffnen
lResult = mciSendString("open " & sFile & _
" type MPEGVideo alias " & sAlias, 0, 0, 0)
If lResult = 0 Then
' MP3 abspielen
If mciSendString("play " & sAlias & _
" from 0", 0, 0, 0) = 0 Then
bResult = True
End If
End If
End If
MP3_Play = bResult
End Function
' Wiedergabe stoppen und MCI schließen
Public Sub MP3_Stop(ByVal sAlias As String)
mciSendString "stop " & sAlias, 0, 0, 0
mciSendString "close " & sAlias, 0, 0, 0
End Sub
Sub losgehts()
MP3_Stop "MyAlias"
MP3_Play ActivePresentation.Path & "\losgehts.mp3", "MyAlias"
End Sub