Click here to Skip to main content
6,595,444 members and growing! (17,399 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Intermediate License: The Code Project Open License (CPOL)

The Ultimate Media Player

By MatrixCoder

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.
VB.NET 2.0, WinXPVS2005, Dev
Posted:21 Nov 2006
Updated:17 Aug 2007
Views:68,262
Bookmarked:43 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
29 votes for this article.
Popularity: 3.29 Rating: 2.25 out of 5
10 votes, 35.7%
1
5 votes, 17.9%
2
1 vote, 3.6%
3
4 votes, 14.3%
4
8 votes, 28.6%
5

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). Now 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 - maximum width is 600 pixels


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 Track Bar, 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

Track Bar

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

Now 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.

Now, 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


Member

Occupation: Software Developer
Location: United States United States

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 32 (Total in Forum: 32) (Refresh)FirstPrevNext
GeneralA few problems Pinmemberoffroaderdan6:38 9 Aug '09  
GeneralRe: A few problems PinmemberMatrixCoder20:31 13 Aug '09  
GeneralRe: A few problems Pinmemberoffroaderdan1:49 27 Aug '09  
GeneralRe: A few problems Pinmemberoffroaderdan4:10 27 Aug '09  
GeneralMy vote of 2 Pinmembersmton16:30 9 Jul '09  
Generalerror in wmp control [modified] Pinmembertads7:09 17 Jun '09  
Questionavi files PinmemberJuraj Chabada23:04 8 Oct '08  
GeneralMultimedia enabled context relative help PinmembercoolestCoder2:42 10 Dec '07  
GeneralThanks Pinmemberaarti8317:57 8 Oct '07  
QuestionDoesn't work PinmemberYauri18:58 28 Sep '07  
AnswerRe: Doesn't work PinmemberMatrixCoder12:34 3 Oct '07  
Generalgood job, but doesn't work on Vista?! PinmemberInfomax14:27 16 Sep '07  
GeneralRe: good job, but doesn't work on Vista?! PinmemberMatrixCoder17:40 18 Sep '07  
GeneralHow to make it work on Vista?! Pinmemberdulcie_liu7:01 30 May '09  
GeneralButton problem Pinmemberflypk9112:12 21 Aug '07  
GeneralRe: Button problem PinmemberMatrixCoder17:13 22 Aug '07  
GeneralRe: Button problem Pinmemberflypk9111:33 2 Sep '07  
GeneralRe: Button problem PinmemberMatrixCoder19:30 2 Sep '07  
GeneralVery Cool but... Pinmemberslammers413:26 13 Aug '07  
GeneralRe: Very Cool but... PinmemberYannou4:23 26 Oct '08  
Generalcool controls PinmemberBosko19784:57 9 Jul '07  
GeneralRe: cool controls PinmemberMatrixCoder9:14 9 Jul '07  
GeneralRe: cool controls PinmemberBosko19789:51 9 Jul '07  
GeneralRe: cool controls PinmemberMatrixCoder13:13 12 Jul '07  
Questionhow did you override the WMP's full scrren controls? Pinmemberbanerjen9:35 7 Jul '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 17 Aug 2007
Editor: Sean Ewington
Copyright 2006 by MatrixCoder
Everything else Copyright © CodeProject, 1999-2009
Web16 | Advertise on the Code Project