Visual Basic III   
 

Opp

 

 

 

 

 

 

 

 

 

Visual Basic: Components

A Guide to using Components - Media Player

Well I assume that you have Visual Basic Loaded, I am going to try to teach you the basics of using components in the form of making a media player. So let's get started.


 

Step 1: Making the "player"

 

Don't worry about the size of your work area we can change this later. Firstly goto Project, then components (ctrl + T), scroll to the very bottom and select "Windows Media Player" click apply and we are ready to start. You should notice that there is now a small icon on your general toolbar (media player icon.) Double click this icon to add the newly loaded component. Resize the media player so that you can only see the play bar. Goto the properties of this media controler set "ShowPositionControl" to false because we won't need these buttons in this project.



 

Step 2: Loading the songs

 

Now we need to load all 3 of these: a "drivelist", "filelist" and a "dirlist" (shown as a hdd icon, folder icon and a piece of paper icon.) Position them into a suitable way to suit your media bar (resize work area if needed.)


 

Step 3: Let's add some code

 

Double click the Drivelist, go back to design mode and double click dirlist.

You should have something like this.

Private Sub Dir1_Change()
End Sub

Private Sub Drive1_Change()
End Sub


Now under Drive1_Change(). Type :   Dir1.Path = Drive1.Drive

Next under Dir1_Change(). Type :   File1.Path = Dir1.Path


*Note you may want to set your filelist to only show mp3's/wav's; if so double click your current form to get Form_load() and type :

File1.Pattern = "*.mp3;*.wav"


You will now have all this code under your belt:

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
File1.Path = Drive1.Drive
End Sub

Private Sub Form_Load()
File1.Pattern = "*.mp3;*.wav"
End Sub

Ok, so you may not have understood fully what has be achieved by this, so why not click your play button to test run the program. Basically we have started to make the loading system for the song that you want to play.


 

Step 4: More code (and it's getting harder...)

 

So you want to go further?

Right you can either make the song play on a single click of it's name, a double or use a seperate button. I chose to do the double click because i thought it was snazzy extra and allows the single click for further advancements of your program.

Start in designer mode, double click the filebox and above the bit where you actually type you will see File1 in one drop down menu and Click change the click to DblClick.

If done right you will get:

Private Sub File1_DblClick()
End Sub

Under File1_DblClick(). Type :   MediaPlayer1.FileName = Dir1.Path & "\" & File1.FileName

This basically tells the media player the location of the song that it can play it.


*Note if you don't want the song to play without you clicking the play button just add: MediaPlayer1.AutoStart = False under File1_DblClick() or Form_Load().


 

Step 5: Finishing up

 

Ok, so your program works all that is left to do is change the form name, I will assume you know how this is done. Remember to comment your code so that later on you can remember what every line means (that's my tip of the day.)


 

Conclusion

 

So you have just made the most basic mediaplayer in the world, this is just an example of how easy it is to make a fully pledged program without having to code your own programs, the final file size is about 20k because it uses activex files that are already in your windows system32 folder.

 

Startside ] Opp ] [Søk]

Copyright © 2002 Øyvind Haugland
Sist endret:  13 januar 2019
 

  Interested in this stuff? Please write to:
 

HTML Counter            stats counter