'How to use the Windows Media Player
'control (version 11.0) in Visual Basic 6.0 to play music
'Date: 15/04/2011
'Author: Aaron Spehr
'Alias: Nightwalker83
'Website: http://aaronspehr.net/
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
Repeat:
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
GoTo Repeat
ElseIf x = vbNo Then
play (s)
mnuPlay.Checked = True
mnuStop.Checked = False
tmrDuration.Enabled = True
End If
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 mnuRewind_Click()
'Rewind the song after pausing
pause
'MediaPlayer1.Controls.fastReverse
mnuRewind.Checked = True
mnuForward.Checked = False
mnuPlay.Checked = False
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 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()
'Displays the current position and the total duration of the current song.
Me.Caption = MediaPlayer1.Controls.currentPositionString + " \ " + MediaPlayer1.currentMedia.durationString + " " + MediaPlayer1.currentMedia.Name
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
End Sub