Tuesday, May 29, 2012

Memainkan file MP3 dengan Windows API di Visual Basic 6

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
lagu As String
lagu = "D:\musik.mp3"

'Kode pada event click tombol cmdPlay
Private Sub cmdPlay_Click()
Call mciSendString("open " & lagu & " type MPEGVideo alias lagu wait", vbNullString, 0&, 0&)
Call mciSendString("play " & lagu , vbNullString,0&, 0&)
End Sub

'Kode pada event click tombol cmdStop
Private Sub cmdStop_Click()
Call mciSendString("stop " & lagu, vbNullString, 0&, 0&)
Call mciSendString("close " & lagu &"wait", vbNullString, 0&, 0&)
End Sub