Option Explicit
Dim s As Integer, x As VbMsgBoxResult, r As Integer
Private Sub Form_Load()
Me.Caption = "Mini MP3 Player"
'Integer index of the song to be played
s = 0
'Disable the song duration timer
tmrDuration.Enabled = False
frmSetup.Songopt(0).Value = True
mnuStop.Checked = True
frmSetup.Caption = "Setup"
End Sub
Private Function play(s)
frmSetup.Lstsongs.Selected(s) = True
MediaPlayer1.URL = frmSetup.Lstsongs.Text
End Function
Private Sub mnuExit_Click()
'Close the player
MediaPlayer1.Close
Unload Me
End Sub
Private Sub mnuForward_Click()
MediaPlayer1.Controls.fastForward
mnuForward.Checked = True
mnuRewind.Checked = False
mnuPlay.Checked = False
End Sub
Private Sub mnuPause_Click()
'Pause the current song
mnuPause.Checked = Not mnuPause.Checked
pause
End Sub
Private Sub mnuPlay_Click()
'If cancel then close the program
'Else choose and play a song
Music1.ShowOpen
frmSetup.Lstsongs.AddItem Music1.FileName
Do
x = MsgBox("Do you want to add more songs?", vbYesNo)
If x = vbYes Then
Music1.ShowOpen
frmSetup.Songopt(1).Value = True
frmSetup.Lstsongs.AddItem Music1.FileName
ElseIf x = vbNo Then
play (s)
mnuPlay.Checked = True
mnuStop.Checked = False
tmrDuration.Enabled = True
Exit Do
End If
Loop
If x = vbNo And frmSetup.Lstsongs.Text = "" Or Err.Number = "32755" Then
'Stop the player
MediaPlayer1.Close
x = vbNo
Unload Me
End If
End Sub
Private Sub pause()
'If mnuPause is not checked continue playing the song
If mnuPause.Checked = False Then
MediaPlayer1.Controls.play
Else
'If mnuPause is checked pause the song
mnuPause.Checked = True
MediaPlayer1.Controls.pause
End If
End Sub
Private Sub mnuRewind_Click()
mnuRewind.Checked = True
mnuForward.Checked = False
mnuPlay.Checked = False
End Sub
Private Sub mnuSettings_Click()
frmSetup.Show vbModal, Me
End Sub
Private Sub mnuStop_Click()
'Stop the player
mnuStop.Checked = True
mnuRewind.Checked = False
mnuForward.Checked = False
mnuPlay.Checked = False
'Disable the song duration timer
tmrDuration.Enabled = False
MediaPlayer1.Controls.stop
frmSetup.Lstsongs.Clear
Me.Caption = "Mini MP3 Player"
End Sub
Private Sub tmrDuration_Timer()
If MediaPlayer1.playState = wmppsStopped And frmSetup.Songopt(1).Value = True And Not s > frmSetup.Lstsongs.ListCount Then
'Play the next song in the list
s = s + 1
play (s)
End If
'Displays the current position and the total duration of the current song.
If Not mnuRewind.Checked = True Then
Me.Caption = MediaPlayer1.Controls.currentPositionString + " \ " + MediaPlayer1.currentMedia.durationString + " " + MediaPlayer1.currentMedia.Name
Else
MediaPlayer1.Controls.currentPosition = MediaPlayer1.Controls.currentPosition - 1
Me.Caption = CStr(MediaPlayer1.currentMedia.duration) + " \ " + CStr(MediaPlayer1.Controls.currentPosition)
End If
End Sub