Click here to Skip to main content
14,880,797 members
Articles / Programming Languages / Visual Basic
Posted 21 Nov 2006


60 bookmarked

The Ultimate Media Player

Rate me:
Please Sign up or sign in to vote.
2.42/5 (34 votes)
17 Aug 2007CPOL1 min read
Have you ever wanted to create a Music/Video Player? Well, now you can. This article will teach you how to create a fully functional general media player.

Sample Image - Screen1.jpg


Playing media isn't hard (at least not in Visual Basic). This tutorial will teach you how to create a fully functional general media player for any use by using the Windows Media Player control.


First, you must insert a Media Player control in your form. (Note: If you cannot find the control, look under "COM Components" in the "Choose Toolbox Items" menu). The Media Player will have its own controls, so to design your own, you will have to remove these by setting the UiMode to None. Next, you will need to add your own controls, like this:

Sample Image

Not only are there "Play, Pause, and Stop" controls, but there are also "Volume, Balance, and Track" controls. The interesting part is the Duration and the TrackBar, which are not as easy as they look.


Dim CurPos As Integer = 
  Convert.ToInt32(PlayerControl.Ctlcontrols.currentPosition * 1000) 
Dim DurationVar As Integer = 
  Convert.ToInt32(PlayerControl.currentMedia.duration * 1000) 
If DurationVar > 0 Then
  PlayBar.Value = Convert.ToInt32((CurPos * 100) / DurationVar) '% complete
End If

'Update the time label
Duration.Text = PlayerControl.Ctlcontrols.currentPositionString


If (PlayerControl.currentMedia.duration <> 0) Then
  Dim NewPerc As Double = Convert.ToDouble(PlayBar.Value) / 100
  Dim DurationVar As Integer = 
    Convert.ToInt32(PlayerControl.currentMedia.duration * 1000) 'milliseconds
  Dim NewPos As Integer = (DurationVar * NewPerc) / 1000

PlayerControl.Ctlcontrols.currentPosition = NewPos
  PlayBar.Value = 0
End If
Catch ex As Exception
End Try

There are a few Media Player properties that are set when the form loads:

PlayerControl.settings.autoStart = True
PlayerControl.settings.volume = VolumeBar.Value
PlayerControl.settings.balance = BalanceBar.Value
PlayerControl.settings.enableErrorDialogs = False
PlayerControl.enableContextMenu = False

Points of Interest

Well, that about wraps it up. Remember that when you add a Media Player to your form, Visual Studio will create two DLL files that are vital to run the program: AxInterop.WMPLib.dll and Interop.WMPLib.dll. Make sure that these are included wherever the main program is.

If you do not want to use Windows Media Player, there is also a Quick Time Control that's available to use (found in the COM Components). However, Quick Time Player must be installed in order to use it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
United States United States
No Biography provided

Comments and Discussions

QuestionWill it run on PC with No Windows Media Player installed Pin
Foji5417-Sep-20 9:29
MemberFoji5417-Sep-20 9:29 
QuestionOOP implementation Pin
sesquipidelian2-Mar-13 15:22
Membersesquipidelian2-Mar-13 15:22 
QuestionVOB File Format Pin
Muhammad Adnan Umar18-Dec-12 23:12
MemberMuhammad Adnan Umar18-Dec-12 23:12 
Questionfps Pin
Member 39252646-Feb-12 3:11
MemberMember 39252646-Feb-12 3:11 
GeneralA few problems Pin
offroaderdan9-Aug-09 5:38
Memberoffroaderdan9-Aug-09 5:38 
GeneralRe: A few problems Pin
MatrixCoder13-Aug-09 19:31
MemberMatrixCoder13-Aug-09 19:31 
GeneralRe: A few problems Pin
offroaderdan27-Aug-09 0:49
Memberoffroaderdan27-Aug-09 0:49 
GeneralRe: A few problems Pin
offroaderdan27-Aug-09 3:10
Memberoffroaderdan27-Aug-09 3:10 
GeneralMy vote of 2 Pin
smton9-Jul-09 15:30
Membersmton9-Jul-09 15:30 
Generalerror in wmp control [modified] Pin
tads17-Jun-09 6:09
Membertads17-Jun-09 6:09 
Questionavi files Pin
Juraj Chabada8-Oct-08 22:04
MemberJuraj Chabada8-Oct-08 22:04 
GeneralMultimedia enabled context relative help Pin
coolestCoder10-Dec-07 1:42
MembercoolestCoder10-Dec-07 1:42 
GeneralThanks Pin
aarti838-Oct-07 16:57
Memberaarti838-Oct-07 16:57 
QuestionDoesn't work Pin
Yauri28-Sep-07 17:58
MemberYauri28-Sep-07 17:58 
AnswerRe: Doesn't work Pin
MatrixCoder3-Oct-07 11:34
MemberMatrixCoder3-Oct-07 11:34 
Generalgood job, but doesn't work on Vista?! Pin
Infomax16-Sep-07 13:27
MemberInfomax16-Sep-07 13:27 
GeneralRe: good job, but doesn't work on Vista?! Pin
MatrixCoder18-Sep-07 16:40
MemberMatrixCoder18-Sep-07 16:40 
GeneralHow to make it work on Vista?! Pin
dulcie_liu30-May-09 6:01
Memberdulcie_liu30-May-09 6:01 
GeneralButton problem Pin
flypk9121-Aug-07 11:12
Memberflypk9121-Aug-07 11:12 
GeneralRe: Button problem Pin
MatrixCoder22-Aug-07 16:13
MemberMatrixCoder22-Aug-07 16:13 
GeneralRe: Button problem Pin
flypk912-Sep-07 10:33
Memberflypk912-Sep-07 10:33 
GeneralRe: Button problem Pin
MatrixCoder2-Sep-07 18:30
MemberMatrixCoder2-Sep-07 18:30 
GeneralVery Cool but... Pin
slammers413-Aug-07 12:26
Memberslammers413-Aug-07 12:26 
GeneralRe: Very Cool but... Pin
Yannou26-Oct-08 3:23
MemberYannou26-Oct-08 3:23 
Generalcool controls Pin
Bosko19789-Jul-07 3:57
MemberBosko19789-Jul-07 3:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.