5,446,542 members and growing! (15,367 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, WinXP, Windows, .NETVisual Studio, VS2005, Dev

Posted: 21 Nov 2006
Updated: 17 Aug 2007
Views: 34,228
Bookmarked: 23 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
23 votes for this Article.
Popularity: 2.65 Rating: 1.95 out of 5
11 votes, 50.0%
1
4 votes, 18.2%
2
1 vote, 4.5%
3
2 votes, 9.1%
4
4 votes, 18.2%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

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



Occupation: Software Developer
Location: United States United States

Other popular VB.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 22 of 22 (Total in Forum: 22) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralMultimedia enabled context relative helpmembercoolestCoder2:42 10 Dec '07  
GeneralThanksmemberaarti8317:57 8 Oct '07  
QuestionDoesn't workmemberYauri18:58 28 Sep '07  
AnswerRe: Doesn't workmemberMatrixCoder12:34 3 Oct '07  
Generalgood job, but doesn't work on Vista?!memberInfomax14:27 16 Sep '07  
GeneralRe: good job, but doesn't work on Vista?!memberMatrixCoder17:40 18 Sep '07  
GeneralButton problemmemberflypk9112:12 21 Aug '07  
GeneralRe: Button problemmemberMatrixCoder17:13 22 Aug '07  
GeneralRe: Button problemmemberflypk9111:33 2 Sep '07  
GeneralRe: Button problemmemberMatrixCoder19:30 2 Sep '07  
GeneralVery Cool but...memberslammers413:26 13 Aug '07  
Generalcool controlsmemberBosko19784:57 9 Jul '07  
GeneralRe: cool controlsmemberMatrixCoder9:14 9 Jul '07  
GeneralRe: cool controlsmemberBosko19789:51 9 Jul '07  
GeneralRe: cool controlsmemberMatrixCoder13:13 12 Jul '07  
Questionhow did you override the WMP's full scrren controls?memberbanerjen9:35 7 Jul '07  
AnswerRe: how did you override the WMP's full scrren controls?memberMatrixCoder13:30 7 Jul '07  
GeneralVersion 2003 plzzmembersteve shafa8:30 18 Dec '06  
GeneralRe: Version 2003 plzzmemberMatrixCoder23:14 1 Jan '07  
GeneralOverstatement?memberBehind The Scene21:33 21 Nov '06  
JokeRe: Overstatement?membertoxcct0:32 22 Nov '06  
GeneralRe: Overstatement?memberJezzBentham20:43 20 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-2008
Web12 | Advertise on the Code Project