Library tutorials & articles

Build an MP3 Player

Playing a File

Up to this point, we have yet to explain how to play an MP3 file. Believe it or not, playing the file is actually the easiest part of this process. To do so, you set the Media Player's FileName property to the file you want to play. That's all there is to it! From this point, you use the media player's built-in buttons to control playing. Listing C shows the code we created for our application.

Listing C: Opening the file

Private Sub cmdOpen_Click()
With MediaPlayer1
	If Not FileOpen Then
		.FileName = FileName
		.AutoStart = False
		cmdOpen.Caption = "Close"
	Else
		.FileName = ""
		cmdOpen.Caption = "Open"
	End If
End With
End Sub

Notice that after setting the FileName property, we chose not to have it start playing automatically, so we set the AutoStart property to False. The code in Listing A stored the currently selected file location in the FileName variable.

Comments

Leave a comment

Sign in or Join us (it's free).

AddThis

Related discussion