VB2022 VB2019 VB6 VB Sample Code About Us

Windows Media Player



This is a VB6 Windows media player that can play all kinds of media files such as wav, midi, mp3, mpeg video, avi video and more. When you launch the program, you can select media files of different types from different sources such as your hard drives, CD and even the URL of a webpage . After you have selected a particular file, you can play it using the customized button or you can use the buttons of the Windows Media Player

In this program, you need to insert the Windows Media Player Control. This control is not available in the default VB6 IDE, you have to press CTRl+T keys to bring up the components dialog, and check the Windows Media Player then click OK, as shown in Figure 1. In addition, you need to insert Microsoft Common Dialog Control 6.0 into the form. This control is also not available in the default IDE, press CTRL+T to bring up the components windows and check on this control, as shown in Figure 2.

Figure 1

Figure 2

Now you are ready to design the player's interface. First, drag the Windows Media Player control into the form and reside it to a certain size. Set its fullScreen property to false. Next, insert Microsoft Common Dialog Control 6.0 in the form and then insert five command buttons in the form. Change the caption of first button to Open, second one to Play, third one to Close, fourth one to Exit and the last one to Full Screen. Finally, insert a text box for the purpose to display the URL of the selected media file. The design would look like the one shown in Figure 3.

Figure 3

For the Open command button, change its name to cmdOpen and enter the following codes:

Private Sub cmdOpen_Click()
Me.CommonDialog1.Filter = "WAV Files (*.wav)|*.wav|" & "MP3 Files (*.mp3)|*.mp3|" & "MP4 Files (*.mp4)|*.mp4|" & "Video Files (*.avi)|*.avi|" &"MPEG Files (*.mpg)|*.mpg|"
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.FileName
End Sub

For the Play button, change its name to cmdPlay and enter the following codes:

Private Sub cmdPlay_Click()
WindowsMediaPlayer1.URL = Text1.Text
End Sub

For the Stop button, change its name to cmdStop and enter the following codes:

Private Sub cmdStop_Click()
WindowsMediaPlayer1.Close
End Sub

For the Full Screen button, change its name to cmdMax and enter the following codes:

Private Sub cmdMax_Click()
WindowsMediaPlayer1.fullScreen = True
End Sub

Now run the program and click on the Open button. A dialog box will appear that allows you to choose your media files, as shown in Figure 4. After selected the file and click on the Play button, it will play the selected media file as shown in Figure 5.

Figure 4

Figure 5

 


Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy