|






|
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
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
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
|
Comments
| 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 - 2008. Last updated
Wednesday 21 May 2008 09:26:11 PM +0100.
|