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.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“You can stand on the shoulders of giants OR a big enough pile of dwarfs, works either way.”