[AccessD] How to play mp3 audio files

Gustav Brock gustav at cactus.dk
Thu Nov 23 05:20:23 CST 2017


Hi Kostas

Not sure what you mean with "insert", but for playback this has worked for me:

<code>
Option Compare Text
Option Explicit

Private Declare PtrSafe Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" ( _
    ByVal lpstrCommand As String, _
    ByVal lpstrReturnString As Any, _
    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 CurrentFile As String
Private PlayStatus  As Long

Public Sub StartSound(ByVal AudioFile As String)

    CurrentFile = GetShortPath(AudioFile)

    PlayStatus = mciSendString("play " & CurrentFile, 0&, 0, 0)

End Sub

Public Sub StopSound(Optional ByVal AudioFile As String)

    If AudioFile = "" Then
        AudioFile = CurrentFile
    End If
    
    PlayStatus = mciSendString("close " & AudioFile, 0&, 0, 0)
    
End Sub

Public Function GetShortPath( _
    ByVal LongPath As String) _
    As String
    
    Dim Length  As Long
    Dim Buffer  As String
    Dim Path    As String
    
    ' Find buffer size.
    Length = GetShortPathName(LongPath, "", 0)
    If Length > 0 Then
        ' Create the buffer.
        Buffer = String(Length, vbNullChar)
        ' Retrieve the short pathname.
        Length = GetShortPathName(LongPath, Buffer, Length)
        ' Remove the trailing null character.
        Path = Left(Buffer, Length)
    End If
    
    GetShortPath = Path
    
End Function
</code>

/gustav

-----Oprindelig meddelelse-----
Fra: AccessD [mailto:accessd-bounces at databaseadvisors.com] På vegne af Kostas Konstantinidis
Sendt: 23. november 2017 10:24
Til: 'Access Developers discussion and problem solving' <accessd at databaseadvisors.com>
Emne: [AccessD] How to play mp3 audio files

Hi all,
Does anybody know how to insert and play audio clips into ms access forms?

Thank's
/kostas 



More information about the AccessD mailing list