martin2k

Home | Forums | VB6 | Games | Software | Directory | HTML | Wiki | Blog | Contact

List Media Player


 

Home

Read and add posts to the Visual Basic 6.0 Forums

Download some of my programs and OCXs

Read the Tips here

The old style forum is still available here

Contact


 

Program

List Media Player is one of the first programs I made.  It is simply a way of browsing through your drives and folders to find media files to play - either sound or video.  The actual player is on a separate Form, which allows for free resizing.

Due to several people asking for the source code, I decided to write this page to explain how the program was made.  You can also look at the source code in this file:


vb_48_listmediaplayer.zip
(5.34 KB)

This project uses two ActiveX controls - Windows Media Player (msdxm.ocx) and Allen OCX (allenocx.ocx).  If you do not have the Windows Media Player control, you will need to download and install Windows Media Player 6.4 (3.42 MB) from Microsoft.  If you are running Windows XP, you should already have this installed.  Allen OCX should be put onto the first Form.

The rest of the controls on the first Form are a FileListBox (called Files), a DirListBox (called Folders), a DriveListBox (called Drives), a ComboBox (called cmbFileTypes) and a CheckBox (called chkRepeat).  You can change the appearance of the controls to match the following screenshot if you wish:

The List Media Player Form
The List Media Player Form

This Form has its BorderStyle property set to 1 - Fixed Single and the MinButton property set to True.

If you want to create the Help menu, the menu items are as follows:

Caption Name Shortcut Key
&Help mnuHelp
...&What to do mnuHelpWhatToDo F1
...&About mnuHelpAbout Ctrl+F1

The List property of the cmbFileTypes ComboBox contains the following text:

*
aif
aifc
aiff
All types
asf
asx
au
avi
m1v
m3u
mid
mov
mp2
mp3
mpa
mpe
mpeg
mpg
qt
ra
ram
rm
rmi
rmm
snd
wav

The second Form looks like this:

The second List Media Player Form containing the Windows Media Player Control
The second List Media Player Form containing the Windows Media Player Control

There is one control on this Form - a Windows Media Player Control called Videoscreen.  The Form itself is called frmVideoform.

Back to the first Form; the code in the Form_Load event is as follows:

Private Sub Form_Load()
On Error GoTo Default

chkRepeat.Value = GetSetting("Martin Allen", "WARM2", "Repeat", 1)
cmbFileTypes.ListIndex = GetSetting("Martin Allen", "WARM2", "FileType", 0)

chkrepeat_Click
cmbFileTypes_Click

Folders.Path = GetSetting("Martin Allen", "WARM2", "Path", App.Path)
Drives.Drive = Folders.Path
Exit Sub

Default:
Folders.Path = App.Path
Drives.Drive = App.Path
cmbFileTypes.ListIndex = 0
chkRepeat.Value = 1

chkrepeat_Click
cmbFileTypes_Click
End Sub

Firstly, settings are retrieved from the registry - the value of chkRepeat, the ListIndex property of the cmbFileTypes ComboBox and the Path of the Folders control.  If an error occurs when trying to do this, default values are set.

The code to browse though the DriveListBox and DirListBox is as follows:

Private Sub Drives_Change()
On Error GoTo Eror

Folders.Path = Drives.Drive
Files.Path = Folders.Path
Exit Sub

Eror:
Drives.Drive = App.Path
End Sub

Private Sub Folders_Change()
Files.Path = Folders.Path
End Sub

If an error occurs when attempting to access a drive, this error is trapped and the Drive is set to the drive that contains the program i.e. App.Path.

When the user clicks on the cmbFileTypes ComboBox, this sets the Pattern property of the FileListBox.  If 'All types' is chosen, the FileListBox displays all the file types that can be played:

Private Sub cmbFileTypes_Click()
If cmbFileTypes.Text = "All types" Then
    Files.Pattern = "*.wav;*.snd;*.au;*.aif;*.aifc;*.aiff;*.mid;*.rmi;*.mp3;*.m3u;" _
    & "*.m1v;*.mp2;*.mpa;*.mpe;*.mpeg;*.asf;*.asx;*.mov;*.qt;*.ra;*.rm;*.ram;*.rmm;*.avi;*.mpg"
Else
    Files.Pattern = "*." & cmbFileTypes.Text
End If
End Sub

Compatible files are played when the user clicks on a file in the FileListBox:

Private Sub Files_Click()
frmVideoform.Show

If Len(Folders.Path) = 3 Then
    frmVideoform.Videoscreen.FileName = Folders.Path & Files.FileName
Else
    frmVideoform.Videoscreen.FileName = Folders.Path & "\" & Files.FileName
End If

chkrepeat_Click
End Sub

When the FileName property of the Windows Media Player control (Videoscreen) is set, it starts playing automatically.

Here is the code for the Help menu items and the Click event for chkRepeat:

Private Sub mnuhelpAbout_Click()
MsgBox "List Media Player V.1.00" & vbCrLf & vbCrLf & "Previously known as WARM - WAV, AVI, RMI, MID", vbInformation, "About List Media Player"
End Sub

Private Sub mnuhelpWhatToDo_Click()
MsgBox "Choose the location of the files with the folder and drive controls and then click on a filename in the filename list box.", vbQuestion, "What to do"
End Sub


Private Sub chkrepeat_Click()
If chkRepeat.Value = vbChecked Then
    frmVideoform.Videoscreen.PlayCount = 0
Else
    frmVideoform.Videoscreen.PlayCount = 1
End If
End Sub

If chkRepeat is detected as being checked, the Windows Media Player control is set to repeat the song by setting the PlayCount property to 0.

When the program closes, frmVideoform is unloaded and settings are saved to the registry:

Private Sub Form_Unload(Cancel As Integer)
Unload frmVideoform
SaveSetting "Martin Allen", "WARM2", "FileType", cmbFileTypes.ListIndex
SaveSetting "Martin Allen", "WARM2", "Repeat", chkRepeat.Value
SaveSetting "Martin Allen", "WARM2", "Path", Folders.Path
End Sub

Here is the code for the second Form.  In the Form_Load event, the Form is set to being the topmost above other windows by using the TopMost method of the Allen control:

Private Sub Form_Load()
frmMainmedia.Allen.TopMost frmVideoform, True
End Sub

Private Sub Form_Resize()
If WindowState = 1 Then Exit Sub
Videoscreen.Top = 0
Videoscreen.Left = 0
Videoscreen.Height = frmVideoform.ScaleHeight
Videoscreen.Width = frmVideoform.ScaleWidth
End Sub


Private Sub Videoscreen_DisplayModeChange()
Left = Videoscreen.Left
Top = Videoscreen.Top
Height = Videoscreen.Height
Width = Videoscreen.Width
End Sub


Private Sub Videoscreen_GotFocus()
frmMainmedia.SetFocus
End Sub


blog comments powered by Disqus

Archived Comments

From: Reynaldo G. Sayo Jr.
Date: Friday, February 4, 2011 at 08:16:35
Comments: Thank you very much ! I like this simple tutorial, I really understand the program with its simple approach. Looking forward for more tutorials like this ! More power ! ^^
 
From: Mutungye
Date: Tuesday, January 18, 2011 at 10:59:31
Comments: This is great, thank you very much.I will greatful to receive your help as i plan to develop a database project to complete my Undergraguate course.May God bless you
 
From: Vitthal vende
Date: Monday, July 12, 2010 at 15:34:15
Comments: Thank's for providing visual Basic 6.0 programes to new genretion. I hope you send me another programe uses in software development.
 
From: Venkat(Best net)
Date: Friday, July 2, 2010 at 05:01:05
Comments: Thank you so much Martin Allen....Really very good work.....
 
From: Florence
Date: Tuesday, February 2, 2010 at 13:21:02
Comments: it's nice,keep it up.would like 2 develop such someday
 
From: IDREES
Date: Sunday, September 27, 2009 at 10:10:53
Comments: Hi Thanks Brother Good Work In Vb ..
 
From: Pasupathy.V
Date: Wednesday, September 16, 2009 at 07:27:23
Comments: Thank q for get this program code.. Its very useful for me...
 
From: tharindu
Date: Wednesday, February 25, 2009 at 10:17:24
Comments: your work is great sir.from Sri Lanka
 
From: Mohammad Javed
Date: Thursday, October 16, 2008 at 11:24:11
Comments: I made a mini project as a Media player so,I take source code related media player.


                                       Thanks you
 
From: faheem
Date: Wednesday, September 17, 2008 at 22:38:07
Comments: hi it is Good
 
From: Rohan Kumar
Date: Wednesday, September 10, 2008 at 13:35:16
Comments: A very nice program.I'm a beginner in VB 6.0, but know enough to understand this program.Well, when i downloaded the program it worked fine.But when I downloaded YOUR code and compiled it using VB 6.0 under the OS Windows XP(SP3). I got errors, see if you can fix those.
 
From: ketan
Date: Saturday, August 30, 2008 at 07:46:16
Comments: this is very useful
 
From: sham
Date: Thursday, July 31, 2008 at 07:50:09
Comments: Thanx buddy ..Keep up u r good work
 
From: ofoefule charles
Date: Monday, June 23, 2008 at 16:22:54
Comments: This work is very nice, i personally consider it a classic. It gives me new ideas.
 
From: deepak
Date: Monday, March 3, 2008 at 10:54:06
Comments: thanks for..............this code
 
From: mohit mishra
Date: Saturday, February 23, 2008 at 13:11:34
Comments: hi,
really u have done a great job. way of representation is too grogeous. thanks a lot. wish u for future success
 
From: Bijay Singh
Date: Sunday, February 17, 2008 at 13:18:53
Comments: It is really Good Refrance . Thanks
  This refrancr is really Student's Helpfull.....
 
From: Rahul
Date: Thursday, January 3, 2008 at 14:06:04
Comments: this code very good for new people.
thank u for the effert
 
From: Khalid Saeed
Date: Tuesday, November 13, 2007 at 12:48:04
Comments: Excellent work in VB programming
keep it up
 
From: salman
Date: Tuesday, October 16, 2007 at 09:43:28
Comments: that's very good prog.thank's a lot.you have a lot of usefull prog's for everybody.
 
From: Jeanc Claude Byungura
Date: Wednesday, October 3, 2007 at 17:36:54
Comments: I'm very happy to receive this information. Actually I'm a bigginer VB 6.0 programming. But need to know more about Visual Basic Programming language. I'm going to try this code if it succeed I'll be sinding you some comments, Stay in touch and thanks a lot
 
From: khawar
Date: Friday, September 14, 2007 at 09:34:31
Comments: i did as described above but i have still problem.it does not play any song.please give me some solution
 
Reply: The best thing to do is to compare your version to the download and then see where you are going wrong.
 
From: Lyon
Date: Monday, September 10, 2007 at 19:21:40
Comments: Thanks for the tutorial i'm most impressed!
 
From: suresh
Date: Monday, July 30, 2007 at 07:00:23
Comments: It helps me to eloborate my VB skill..
 
From: blar
Date: Thursday, July 12, 2007 at 08:58:06
Comments: thanks, this will help me in my class project
 
From: sufi
Date: Saturday, June 30, 2007 at 09:26:37
Comments: thanks ................for this code.
 
From: tran van hoanh
Date: Sunday, April 15, 2007 at 02:50:48
Comments: That's very good code
Thanks
 
From: Shahid +(92)3339731860
Date: Monday, April 9, 2007 at 10:32:29
Comments: Your web site is very gratful.
I want to learn more coding from it.



Thanks.......................Martin
 
From: Jayasankar
Date: Friday, November 10, 2006 at 17:20:03
Comments: Thanks,I am looking for how to use vb controlls after a long search in google I found your site I thank you for this code
 
From: Essie Lee
Date: Wednesday, July 19, 2006 at 01:22:19
Comments: I think this program will be very useful to me. So will help me learn how to do it. Thank you
 
From: Prashath
Date: Friday, June 9, 2006 at 09:06:04
Comments: Nice work, you'd better do more features
 
From: ajay mistry
Date: Thursday, April 20, 2006 at 17:19:14
Comments: I think I'm going to learn much coding using this URL
 
From: Javeed Abdullah
Date: Wednesday, March 29, 2006 at 19:35:27
Comments: This program is good because it play more than three format files usally we got some for one and two format but that work or not we do not know and how to use in programm.
 
From: Alain A. Preglo
Date: Wednesday, September 28, 2005 at 08:50:11
Comments: Thank you very much the second program that give Martin Allen. Hope that you send me another program in visual basic and in C++.

thanxs...............!!!!!!!!!!!


Martin Allen 1999 - 2011.  Last updated Thursday 11 August 2011 08:44:43 PM +0100.