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

  1. 25 Aug 2009 at 02:30

    What version of VB are you running in order to rpoduce this player? I am running VB6 at the moment and cannot compile this player, any chance of rewriting the script for Vb6 for me please as i am only new to Vb and still trying to learn.

    Thanks, Jameson

Leave a comment

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

ElementK Journals
AddThis

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

We'd love to hear what you think! Submit ideas or give us feedback