RSS

Jalankan MP3 dengan VB 6.0 (bag.2)

Jalankan MP3 tanpa OCX (bag.2)

Pada artilkel sebelumnya, kita telah mendeklarasikan hal-hal yang diperlukan. sekarang ini, masuklah kita kepada menulis fugnsi-fungsi yang diperlukan dan mencegat beberapa event.

Fungsi yang diperlukan adalah:


Public Function MP3Play(wndHandle As Long,
sFileName As String)
Dim cmdToDo As String * 255
Dim dwReturn As Long
Dim ret As String * 128
Dim tmp As String * 255
Dim lenShort As Long
Dim ShortPathAndFie As String, glo_HWND As Long
If Dir(sFileName) = "" Then
mmOpen = "Error with input file"
Exit Function
End If
lenShort = GetShortPathName(sFileName, tmp, 255)
ShortPathAndFie = Left$(tmp, lenShort)
glo_HWND = wndHandle
cmdToDo = "open " & ShortPathAndFie & " type
MPEGVideo Alias MP3Play"
dwReturn = mciSendString(cmdToDo, 0&, 0&, 0&)
If dwReturn <> 0 Then 'not success
mciGetErrorString dwReturn, ret, 128
mmOpen = ret
MsgBox ret, vbCritical
Exit Function
End If
mmOpen = "Success"
mciSendString "play MP3Play", 0, 0, 0
End Function
Public Function MP3Pause()
mciSendString "pause MP3Play", 0, 0, 0
End Function
Public Function MP3UnPause()
mciSendString "play MP3Play", 0, 0, 0
End Function
Public Function MP3Stop() As String
mciSendString "stop MP3Play", 0, 0, 0
mciSendString "close MP3Play", 0, 0, 0
End Function
Private Sub Open_file()
CommonDialog1.Filter = "MP3 Files *.mp3"
CommonDialog1.ShowOpen
nFileName = CommonDialog1.FileName
Text1.Text = nFileName
MP3Play hWnd, nFileName
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Exit Sub

ex:
Command1.Enabled = True
Command5.Enabled = True
End Sub
Pemrograman
Public Function IsPlaying() As Boolean
Static s As String * 30
mciSendString "status MP3Play mode", s, Len(s), 0
IsPlaying = (Mid$(s, 1, 7) = "playing")
End Function
4) Sedangkan event-event yang dicegat adalah:Private Sub Check1_Click()
Timer1 = Not Timer1
If Timer1 Then Check1.Value = 1 Else Check1.
Value = 0
End Sub
Private Sub Command1_Click()
Command1.Enabled = False
Command5.Enabled = False
Open_file
End Sub
Private Sub Command2_Click()
If Command2.Caption = "Pause" Then
Command2.Caption = "Play"
MP3Pause
Else
Command2.Caption = "Pause"
MP3UnPause
End If
End Sub
Private Sub Command3_Click()
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command1.Enabled = True
Command2.Caption = "Pause"
MP3Stop
End Sub
Private Sub Command4_Click()
mciSendString "stop MP3Play", 0, 0, 0
mciSendString "play MP3Play from 0", 0, 0, 0
Command2.Caption = "Pause"
End Sub
Private Sub Command5_Click()
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
MP3Stop
End Sub

5) Simpan, dan jalankan program. Selamat Mencoba....!!

Ohya, baca juga artikel: Nissan X-trail Mobil SUV Tangguh dan Sporty Terbaik

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

1 komentar:

Anonim mengatakan...

thanks bwt share nya!

Posting Komentar