Click here to Skip to main content
12,445,025 members (51,809 online)
Click here to Skip to main content
Add your own
alternative version

Stats

139.2K views
8.9K downloads
60 bookmarked
Posted

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

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionOOP implementation Pin
sesquipidelian2-Mar-13 15:22
membersesquipidelian2-Mar-13 15:22 
How do you implement object oriented programming with the codes above? is there a way?
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 
GeneralRe: cool controls Pin
MatrixCoder9-Jul-07 8:14
memberMatrixCoder9-Jul-07 8:14 

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.

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