Click here to Skip to main content
Click here to Skip to main content

The Ultimate Media Player

, 17 Aug 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
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

Introduction

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.

Begin

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.

Duration

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

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

TrackBar

Try
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
Else
  PlayBar.Value = 0
End If
Catch ex As Exception
  MsgBox(ex.Message)
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.

License

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

Share

About the Author

MatrixCoder
Software Developer
United States United States
No Biography provided

Comments and Discussions

 
QuestionOOP implementation Pinmembersesquipidelian2-Mar-13 16:22 
How do you implement object oriented programming with the codes above? is there a way?
QuestionVOB File Format PinmemberMuhammad Adnan Umar19-Dec-12 0:12 
Questionfps PinmemberMember 39252646-Feb-12 4:11 
GeneralA few problems Pinmemberoffroaderdan9-Aug-09 6:38 
GeneralRe: A few problems PinmemberMatrixCoder13-Aug-09 20:31 
GeneralRe: A few problems Pinmemberoffroaderdan27-Aug-09 1:49 
GeneralRe: A few problems Pinmemberoffroaderdan27-Aug-09 4:10 
GeneralMy vote of 2 Pinmembersmton9-Jul-09 16:30 
Generalerror in wmp control [modified] Pinmembertads17-Jun-09 7:09 
Questionavi files PinmemberJuraj Chabada8-Oct-08 23:04 
GeneralMultimedia enabled context relative help PinmembercoolestCoder10-Dec-07 2:42 
GeneralThanks Pinmemberaarti838-Oct-07 17:57 
QuestionDoesn't work PinmemberYauri28-Sep-07 18:58 
AnswerRe: Doesn't work PinmemberMatrixCoder3-Oct-07 12:34 
Generalgood job, but doesn't work on Vista?! PinmemberInfomax16-Sep-07 14:27 
GeneralRe: good job, but doesn't work on Vista?! PinmemberMatrixCoder18-Sep-07 17:40 
GeneralHow to make it work on Vista?! Pinmemberdulcie_liu30-May-09 7:01 
GeneralButton problem Pinmemberflypk9121-Aug-07 12:12 
GeneralRe: Button problem PinmemberMatrixCoder22-Aug-07 17:13 
GeneralRe: Button problem Pinmemberflypk912-Sep-07 11:33 
GeneralRe: Button problem PinmemberMatrixCoder2-Sep-07 19:30 
GeneralVery Cool but... Pinmemberslammers413-Aug-07 13:26 
GeneralRe: Very Cool but... PinmemberYannou26-Oct-08 4:23 
Generalcool controls PinmemberBosko19789-Jul-07 4:57 
GeneralRe: cool controls PinmemberMatrixCoder9-Jul-07 9:14 
GeneralRe: cool controls PinmemberBosko19789-Jul-07 9:51 
GeneralRe: cool controls PinmemberMatrixCoder12-Jul-07 13:13 
Questionhow did you override the WMP's full scrren controls? Pinmemberbanerjen7-Jul-07 9:35 
AnswerRe: how did you override the WMP's full scrren controls? PinmemberMatrixCoder7-Jul-07 13:30 
GeneralVersion 2003 plzz Pinmembersteve shafa18-Dec-06 8:30 
GeneralRe: Version 2003 plzz PinmemberMatrixCoder1-Jan-07 23:14 
GeneralRe: Version 2003 plzz PinmemberTony Cooper10-Mar-09 21:43 
QuestionOverstatement? PinmemberBehind The Scene21-Nov-06 21:33 
AnswerRe: Overstatement? Pinmembertoxcct22-Nov-06 0:32 
AnswerRe: Overstatement? PinmemberJezzBentham20-Jul-07 20:43 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150129.1 | Last Updated 17 Aug 2007
Article Copyright 2006 by MatrixCoder
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid