Music Player

Pada kesempatan kali ini saya akan jelaskan bagaimana caranya membuat aplikasi pemutar music yang sederhana.
Langkah-langkahnya adalah:

. Buka Microsoft Visual Basic. Klik start All Program Microsoft Visual Studio Microsoft Visual Basic 6.0
. Kemudia akan tampil Jendela New Project (Gambar 1) kemudian pilih Standart EXE. Klik Open.
. Kemudian akan tampil Area Kerja.
1. Form
2. Project Explorer
3. Properties
4. Toolbox
4. Tambahkan 3 komponen pada Toolbox. Klik kanan di toolbox Components…
5. Ceklis pada Microsoft Common Control Dialog 6.0 (SP.6), Mirosoft Windows Common Controls 6.0 (SP.6). dan Windows Media Player Klik OK. (Gambar 3).

6. Tambahkan 2 komponen Label di dalam Form, dua buah Timer, 5 CommandButton, 1 buah PictureBox dan 1 buah ListView serta 1 buah CommonDialog.
7. PictureBoxTempatkan agar sesuai dengan Gambar 4.

8. Ubah propertiesnya seperti di bawah ini.

kemudian ketikan syntak seperti di bawah ini!

Option Explicit
Dim lokasi As String
Dim tmpDurasi As String
Dim i As Integer
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdNext_Click()
If lvwLagu.SelectedItem.Index = i Then
cmdStop_Click
lokasi = lvwLagu.ListItems(1)
lvwLagu.ListItems(1).Selected = True
cmdPlay_Click
Else
cmdStop_Click
lokasi = lvwLagu.ListItems(lvwLagu.SelectedItem.Index + 1)
cmdPlay_Click
lvwLagu.ListItems(lvwLagu.SelectedItem.Index + 1).Selected = True
cmdPlay_Click
End If
End Sub
Private Sub cmdPlay_Click()
On Error GoTo pesan
If cmdPlay.Caption = “> Play” Then
If cmdPlay.Caption = “> Play” Then
cmdPlay.Caption = ” Pause”
wmpPlayer.URL = lokasi
Timer1.Enabled = True
Timer2.Enabled = True
Else
wmpPlayer.Controls.play
cmdPlay.Caption = ” Pause”
End If
Else
wmpPlayer.Controls.pause
cmdPlay.Caption = “> Play”
End If
Exit Sub
pesan:
MsgBox “Pilih lagunya dulu!!”, vbOKOnly + vbInformation, “Lagu kosong”
cmdPlay.Caption = “> Play”
End Sub
Private Sub cmdPrev_Click()
If lvwLagu.SelectedItem.Index = 1 Then
Exit Sub
Else
cmdStop_Click
lokasi = lvwLagu.ListItems(lvwLagu.SelectedItem.Index – 1)
cmdPlay_Click
lvwLagu.ListItems(lvwLagu.SelectedItem.Index – 1).Selected = True
cmdPlay_Click
End If
End Sub
Private Sub cmdStop_Click()
wmpPlayer.Controls.stop
End Sub
Private Sub cmdTambah_Click()
Dim lis As ListItem
With dlgMusic
.DialogTitle = “Insert Song”
.Filter = “Support File ” & “(*.mp3;*.mid;*.wav;*.mp4)” & “*.mp3;*.mid;*.wav;*.mp4″
.ShowOpen
Set lis = lvwLagu.ListItems.Add(, , .FileTitle)
lis.SubItems(1) = .FileName
End With
i = lvwLagu.ListItems.Count
If lokasi <> “” Then
Exit Sub
Else
lokasi = dlgMusic.FileName
End If
End Sub
Private Sub Form_DblClick()
Timer2.Enabled = True
End Sub
Private Sub Form_Load()
buatTable
i = 1
End Sub
Private Sub lvwLagu_DblClick()
cmdStop_Click
lokasi = lvwLagu.SelectedItem.ListSubItems(1)
cmdPlay_Click
End Sub
Private Sub Timer1_Timer()
lblDurasi.Caption = wmpPlayer.Controls.currentPositionString
tmpDurasi = wmpPlayer.currentMedia.durationString
lblJudul.Caption = wmpPlayer.currentMedia.Name
If lblDurasi.Caption = “” Then
cmdNext_Click
End If
End Sub
Private Sub Timer2_Timer()
If lblJudul.Left < Picture1.Width – Picture1.Width – lblJudul.Width Then
lblJudul.Left = Picture1.Width – 1
lblJudul.Left = lblJudul.Left – 5
Else
lblJudul.Left = lblJudul.Left – 5
End If
End Sub
Sub buatTable()
With lvwLagu.ColumnHeaders
.Clear
.Add , , “Lagu”, 5000
.Add , , “”, 0
End With
End Sub
Good luck....
Blog, Updated at: 4/26/2011 09:21:00 AM

0 comments:

Post a Comment

ROUGER DELUFFY CHANNEL