Mp3Play




Dim pos, pos2, dragg As Boolean
Private Sub Command1_Click()
'show only mp3's in the open window

CommonDialog1.Filter = "MP3 Files|*.mp3"
'show the open window

CommonDialog1.ShowOpen
'load an mp3 into media player

temp$ = CommonDialog1.FileName
If temp$ <> "" Then MediaPlayer1.FileName = temp$
End Sub

Private Sub Form_Load()
'set the sliders position and draw the slider

pos = 45
Line (pos, 40)-(pos + 200, 200), , BF
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'if the slider is clicked on the disable the timer and enable dragging

If X >= pos And X <= pos + 200 And Y >= 40 And Y <= 200 Then dragg = True: Timer1.Enabled = False
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If dragg = True Then
'clear the form

Cls
'the next 2 lines prevent the slider from going

'outside of its range

If X <= 145 Then X = 145
If X >= 2045 Then X = 2045
'draw the slider

Line (X - 100, 40)-(X + 100, 200), , BF
'set the position

pos = X - 100
End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'disable dragging

dragg = False
'get the new position at which media player should play

On Error Resume Next
pos2 = Round(pos - 45) / Int(2000 / (MediaPlayer1.Duration))
'check if its below 0

If pos2 < 0 Then pos2 = 0
'check if its greater than duration

If pos2 > MediaPlayer1.Duration Then pos2 = MediaPlayer1.Duration
'set the position

MediaPlayer1.CurrentPosition = pos2
'enbable the timer

Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
'clear the screen

Cls
'draw the slider

Line (pos, 40)-(pos + 200, 200), , BF
On Error Resume Next
'set new point for the slider

pos = 45 + (Int(MediaPlayer1.CurrentPosition) * Int(2000 / (MediaPlayer1.Duration)))
'prevent it from going outside of its range

If pos + 200 >= 2145 Then pos = 1945
End Sub

Richiede MEdiaPlayer










( mp3play.html )- by Paolo Puglisi - Modifica del 17/12/2023