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:
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:
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
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 ! ^^
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
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.
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
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.