Click here to Skip to main content
Licence CPOL
First Posted 21 Nov 2006
Views 103,892
Downloads 2,699
Bookmarked 58 times

The Ultimate Media Player

By | 17 Aug 2007 | Article
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)

About the Author

MatrixCoder

Software Developer

United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionfps PinmemberMember 39252643:11 6 Feb '12  
GeneralA few problems Pinmemberoffroaderdan5:38 9 Aug '09  
GeneralRe: A few problems PinmemberMatrixCoder19:31 13 Aug '09  
GeneralRe: A few problems Pinmemberoffroaderdan0:49 27 Aug '09  
GeneralRe: A few problems Pinmemberoffroaderdan3:10 27 Aug '09  
GeneralMy vote of 2 Pinmembersmton15:30 9 Jul '09  
Generalerror in wmp control [modified] Pinmembertads6:09 17 Jun '09  
Questionavi files PinmemberJuraj Chabada22:04 8 Oct '08  
GeneralMultimedia enabled context relative help PinmembercoolestCoder1:42 10 Dec '07  
GeneralThanks Pinmemberaarti8316:57 8 Oct '07  
QuestionDoesn't work PinmemberYauri17:58 28 Sep '07  
AnswerRe: Doesn't work PinmemberMatrixCoder11:34 3 Oct '07  
Generalgood job, but doesn't work on Vista?! PinmemberInfomax13:27 16 Sep '07  
GeneralRe: good job, but doesn't work on Vista?! PinmemberMatrixCoder16:40 18 Sep '07  
GeneralHow to make it work on Vista?! Pinmemberdulcie_liu6:01 30 May '09  
GeneralButton problem Pinmemberflypk9111:12 21 Aug '07  
GeneralRe: Button problem PinmemberMatrixCoder16:13 22 Aug '07  
GeneralRe: Button problem Pinmemberflypk9110:33 2 Sep '07  
GeneralRe: Button problem PinmemberMatrixCoder18:30 2 Sep '07  
GeneralVery Cool but... Pinmemberslammers412:26 13 Aug '07  
GeneralRe: Very Cool but... PinmemberYannou3:23 26 Oct '08  
Generalcool controls PinmemberBosko19783:57 9 Jul '07  
GeneralRe: cool controls PinmemberMatrixCoder8:14 9 Jul '07  
GeneralRe: cool controls PinmemberBosko19788:51 9 Jul '07  
GeneralRe: cool controls PinmemberMatrixCoder12:13 12 Jul '07  

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.

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