by DeepSea (1 Submission)
Category: Sound/MP3
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 19th March 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This code will play an mp3/wav file without the need of the MM control. This code was found and modified to fix a couple of bugs. The
API Declarations
'This is required when using the winmm.dll because the dll has problems when the filename has spaces! this is a system function that translates a path to the short name!
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
'Declaration for the winmm dll
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
Dim FileName As String
Dim Paused As Boolean
mciSendString "Close MM", 0, 0, 0
mciSendString "Open " & FileName & " Alias MM", 0, 0, 0
mciSendString "Play MM", 0, 0, 0
End Function
Private Function Pause_MM()
If Paused = False Then
mciSendString "Pause MM", 0, 0, 0
Paused = True
Else
mciSendString "Play MM", 0, 0, 0
Paused = False
End If
End Function
Private Function Stop_MM()
mciSendString "Stop MM", 0, 0, 0
mciSendString "Close MM", 0, 0, 0
End Function
Private Sub Next_Click()
On Error Resume Next
Stop_MM
If Text2.Text <> "" Then Name List1.List(0) As Text2.Text & "\" & GetFileName(List1.List(0))
List1.RemoveItem (0)
Play_Click
End Sub
Private Sub Play_Click()
FileName = List1.List(0)
If InStr(1, FileName, " ") > 0 Then FileName = Short_Name(FileName)
Play_MM
End Sub
Private Sub Stop_Click()
Stop_MM
End Sub
Private Function GetFileName(File As String) As String
Dim temp
temp = File
temp = StrReverse(temp)
temp = Left(temp, InStr(1, temp, "\") - 1)
temp = StrReverse(temp)
GetFileName = temp
End Function
Public Function Short_Name(Long_Path As String) As String
'Returns short pathname of the passed lo
' ng pathname
Dim Short_Path As String
Dim PathLength As Long
Short_Path = Space(250)
PathLength = GetShortPathName(Long_Path, Short_Path, Len(Short_Path))
If PathLength Then
Short_Name = Left$(Short_Path, PathLength)
End If
End Function
No comments have been posted about This code will play an mp3/wav file without the need of the MM control. This code was found and mod. Why not be the first to post a comment about This code will play an mp3/wav file without the need of the MM control. This code was found and mod.