Play MP3 Files Using Windows Media Player

You can use Microsoft Windows Media Player in your VB application to play MP3 files.
To do that you must have Windows Media Player installed on your computer.

Preparations

Add Windows Media Player to your form:
From VB menu choose Project->Components... then mark the Windows Media Player check box and press OK. Now drag the Windows Media Player Control to your form.

If you want that Windows Media Player will be invisible, set its Visible property to False.

Add 3 Command Buttons to your form.
Press the first to play the MP3 file, press the second to stop it, and press the third to Pause/Resume.

Form Code

Private Sub Command1_Click()
' replace the "D:\MP3\MyFile.mp3" below with the Mp3 file
' you want to play

    MediaPlayer1.Open "D:\MP3\MyFile.mp3"
End Sub

Private Sub Command2_Click()
    MediaPlayer1.Stop
End Sub

Private Sub Command3_Click()
' if PlayState is 2: the file is currently playing.
' if PlayState is 1: the file is in pause mode.
   
If MediaPlayer1.PlayState = 2 Then
        MediaPlayer1.Pause
    Else
        MediaPlayer1.Play
    End If
End Sub

Go Back