VB 2008 Tutorial - Featured Media Player

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
27 posts Page 1 of 3
User avatar
tvs praveen
Top Poster
Top Poster
Posts: 205
Joined: Tue Dec 08, 2009 6:20 am

Hi, Now i`m gonna show you how to make your own too advanced and featured Media Player in VB.NET

Insert 1 Media Player, 13 Buttons, 1 ScrollBar, 1 Timer, 1 ListBox, 2 Checkbox, 2 TrackBar, 6 label and a OpenFileDialog :P

In properties rename all the buttons text into following below

Button1 into Play

Button2 into Pause

Button3 into Undo Pause

Button4 into Stop

Button5 into Next

Button6 into Previous

Button7 into Full Screen

Button8 into Import Media Files into Media PlayList

Button9 into Clear Media PlayList

Button10 into Play All Files

Button11 into Save Playist

Button12 into Load PlayList

Button13 into Shuffle

Now in Properties rename text of the Labels as following below

Name a Label1 text into Media Player Screen

Name a Label2 text into Media PlayList

Name a Label3 text into Audio Volume

Name a Label4 text into Audio balance

Name a Label5 text into 00:00

Name a Label6 text into ...

Place all the Labels as you wish! ;)

Design your Media Player looks as you wish, Then now start coding! ;)

Double click and insert this code into Button1
Code: Select all
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
Double click and insert this code into Button2
Code: Select all
AxWindowsMediaPlayer1.Ctlcontrols.pause()
Double click and insert this code into Button3
Code: Select all
AxWindowsMediaPlayer1.Ctlcontrols.play()
Double click and insert this code into Button4
Code: Select all
AxWindowsMediaPlayer1.Ctlcontrols.stop()
Double click and insert this code into Button5
Code: Select all
Dim TrackRandom As Integer
TrackRandom = Int((ListBox1.Items.Count))
AxWindowsMediaPlayer1.Ctlcontrols.next()
Double click and insert this code into Button6
Code: Select all
Dim TrackRandom As Integer
TrackRandom = Int((ListBox1.Items.Count))
AxWindowsMediaPlayer1.Ctlcontrols.previous()
Double click and insert this code into Button7
Code: Select all
AxWindowsMediaPlayer1.fullScreen = True
Double click and insert this code into Button8
Code: Select all
OpenFileDialog1.ShowDialog()
Double click and insert this code into Button9
Code: Select all
ListBox1.Items.Clear()
Double click and insert this code into Button10
Code: Select all
Dim TrackURL
Dim Playlist As WMPLib.IWMPPlaylist = AxWindowsMediaPlayer1.newPlaylist("MyPlayList", "")
For Each TrackURL In ListBox1.Items
Playlist.appendItem(AxWindowsMediaPlayer1.newMedia(TrackURL))
Next
AxWindowsMediaPlayer1.currentPlaylist = Playlist
AxWindowsMediaPlayer1.Ctlcontrols.play()
Double click and insert this code into Button11
Code: Select all
Dim FileWriter As StreamWriter
Dim results As DialogResult
results = SaveFileDialog1.ShowDialog
If results = DialogResult.OK Then
FileWriter = New StreamWriter(SaveFileDialog1.FileName, False)
End If
Double click and insert this code into Button12
Code: Select all
Dim oresults As DialogResult
oresults = OpenFileDialog2.ShowDialog()
If oresults = Windows.Forms.DialogResult.OK Then
Dim ioFile As New StreamReader(OpenFileDialog2.FileName)
Dim ioLine As String
Dim ioLines As String
ioLine = ioFile.ReadLine
ListBox1.Items.Add(ioLine)
ioLines = ioLine
While Not ioLine = ""
ioLine = ioFile.ReadLine
ioLines = ioLines & vbCrLf & ioLine
If ioLine <> "" Then
ListBox1.Items.Add(ioLine)
End If
End While
ioFile.Close()
End If
Double click and insert this code into Button13
Code: Select all
Dim TrackRandom As Integer
                TrackRandom = Int((ListBox1.Items.Count) * Rnd())
                AxWindowsMediaPlayer1.URL = (ListBox1.Items(TrackRandom)) 
In Properties of ScrollBar1 make TabIndex into 6

Double click ScrollBar1 and insert this code into it
Code: Select all
Try
If (AxWindowsMediaPlayer1.currentMedia.duration <> 0) Then
Dim NewPerc As Double = Convert.ToDouble(ScrollBar1.Value) / 100
Dim DurationVar As Integer = Convert.ToInt32(AxWindowsMediaPlayer1.currentMedia.duration * 1000)
Dim NewPos As Integer = (DurationVar * NewPerc) / 1000
AxWindowsMediaPlayer1.Ctlcontrols.currentPosition = NewPos
Else
ScrollBar1.Value = 0
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
In Properties of Timer1 make Enabled into True and make Interval into 1124

Double click Timer1 and insert this code into it
Code: Select all
If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsPlaying Then
            Select Case track
                Case "0"
                    Label6.Text = "Title: " & AxWindowsMediaPlayer1.currentMedia.getItemInfo("title")
                    track += 1
                Case "1"
                    Label6.Text = "Artist: " & AxWindowsMediaPlayer1.currentMedia.getItemInfo("artist")
                    track += 1
                Case "2"
                    Label6.Text = "Genre: " & AxWindowsMediaPlayer1.currentMedia.getItemInfo("genre")
                    track += 1
                Case "3"
                    Label6.Text = "Media Name: " & AxWindowsMediaPlayer1.currentMedia.name
                    track += 1
                Case "4"
                    Label6.Text = "Duration: " & AxWindowsMediaPlayer1.Ctlcontrols.currentPositionString
                    track += 1
                Case "5"
                    Label6.Text = "File Path: " & AxWindowsMediaPlayer1.currentMedia.sourceURL
                    track += 1
                Case "6"
                    Label6.Text = "Media Code: " & AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
                    track += 1
                Case "7"
                    Label6.Text = "Time: " & TimeOfDay
                    track += 1
                Case "8"
                    Label6.Text = "Date: " & DateString
                    track = 0
                Case Else
                    Label6.Text = "..."
                End Select
            If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsStopped Then
                Label6.Text = "Player Stopped..."
            End If
        End If
Rename a text of CheckBox1 into Mute Audio

Double click and insert this code into CheckBox1
Code: Select all
If CheckBox1.Checked = True Then
AxWindowsMediaPlayer1.settings.volume = 0
Else
AxWindowsMediaPlayer1.settings.volume = 100
End If
In Properties of CheckBox2 make text into Enable Repeat

Double click CheckBox2 and insert this code into it
Code: Select all
If CheckBox1.Checked = True Then
AxWindowsMediaPlayer1.settings.setMode("loop", True)
Else
AxWindowsMediaPlayer1.settings.setMode("loop", False)
End If
Make a TrackBar1 Maximum into 100

Make a TrackBar1 Minimum into 0

Make a TrackBar1 value into 100

Make a TrackBar2 Maximum into 100

Make a TrackBar2 Minimum into 0

Make a TrackBar2 value into 100

Double click and insert this code into TrackBar1
Code: Select all
AxWindowsMediaPlayer1.settings.volume = TrackBar1.Value
Double click and insert this code into TrackBar2
Code: Select all
AxWindowsMediaPlayer1.settings.balance = TrackBar2.Value
Insert this at very top above Public Class Form1
Code: Select all
Imports System.IO
Insert this at below Public Class Form1
Code: Select all
Private PlayAgain As Boolean
Public track = 0
Double click Form and insert this code into it
Code: Select all
AxWindowsMediaPlayer1.settings.volume = TrackBar1.Value
AxWindowsMediaPlayer1.settings.balance = TrackBar2.Value
Insert this text in OpenFileDialog1 Properties Filename and in Title
Code: Select all
Import Media File(s) into Media PlayList
Insert this in OpenFileDialog1 Properties Filter
Code: Select all
All Type Of Media Files|*.*|MPG2 Media Files [MPG]|*.mpg|Windows Media Video [WMV]|*.wmv|DIVX Media Files [DIVX]|*.divx|MOV Media Files [MOV|*.mov|Flash Video [FLV]|*.flv
Double click and insert this code into OpenFileDialog1
Code: Select all
For Each track As String In OpenFileDialog1.FileNames
ListBox1.Items.Add(track)
Next
Double click and insert this code into ListBox1
Code: Select all
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
Now debug, Your`s superb Advanced Featured Media Player is ready! cooll;


*******************Thanks for reading my tutorial, I think this Tutorial will be most helpful to you!*******************

If you want any custom tutorial for you or you need any help in VS.NET, VB.NET, Software Coding, Designing and much more any help in Computer stuffs just ask me

Mostly i will help everyone in coding and design stuffs in on Computer

- Best regards hehaho;

- Tvs Praveen wahooo;

- Thanks CodeNStuff! for this amazing Website cooll;
Last edited by tvs praveen on Sat Jan 23, 2010 6:07 am, edited 2 times in total.
User avatar
geenID
New Member
New Member
Posts: 15
Joined: Mon Dec 21, 2009 5:56 pm

very nice man, really thanks for this :D BUT..
i have a problem..
If a hit the button: load playlist, and i choose a mp3 file, get I this message:
"Exception from HRESULT: 0xC00D1325"
Can you help me please ? :D
User avatar
tvs praveen
Top Poster
Top Poster
Posts: 205
Joined: Tue Dec 08, 2009 6:20 am

geenID wrote:
very nice man, really thanks for this :D BUT..
i have a problem..
If a hit the button: load playlist, and i choose a mp3 file, get I this message:
"Exception from HRESULT: 0xC00D1325"
Can you help me please ? :D
This Media Player features will 100 % works well, Note: If you open MP3 or any other Audio file from "Load PlayList" will never work, "Load PLayList" button feature is given to only load PlayList type fromats not to load Audio files, To open any other Media files click "Import Media File" Button :D
Last edited by tvs praveen on Fri Jan 22, 2010 6:22 pm, edited 1 time in total.
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

geenID wrote:
very nice man, really thanks for this :D BUT..
i have a problem..
If a hit the button: load playlist, and i choose a mp3 file, get I this message:
"Exception from HRESULT: 0xC00D1325"
Can you help me please ? :D
Maybe because Loading Playlist button is made for Loading playlists and not MP3 files... hehaho;
User avatar
tvs praveen
Top Poster
Top Poster
Posts: 205
Joined: Tue Dec 08, 2009 6:20 am

Nery wrote:
geenID wrote:
very nice man, really thanks for this :D BUT..
i have a problem..
If a hit the button: load playlist, and i choose a mp3 file, get I this message:
"Exception from HRESULT: 0xC00D1325"
Can you help me please ? :D
Maybe because Loading Playlist button is made for Loading playlists and not MP3 files... hehaho;
Yes your right Nery
Lewis
Coding God
Coding God
Posts: 1564
Joined: Sun Dec 20, 2009 2:12 pm

This looks good :D
Image
Lewis
Coding God
Coding God
Posts: 1564
Joined: Sun Dec 20, 2009 2:12 pm

You need 13 buttons?
Image
User avatar
tvs praveen
Top Poster
Top Poster
Posts: 205
Joined: Tue Dec 08, 2009 6:20 am

lewisfroom wrote:
You need 13 buttons?

Yes, 13 Buttons for 13 different features! wahooo;
User avatar
geenID
New Member
New Member
Posts: 15
Joined: Mon Dec 21, 2009 5:56 pm

ok thanks, but how must i resolve this problem?

btw; SOURCE CODE for BUTTON 13 is missing :)
Lewis
Coding God
Coding God
Posts: 1564
Joined: Sun Dec 20, 2009 2:12 pm

Yeah not a good tutorial since some errors come up
Image
27 posts Page 1 of 3
Return to “Tutorials”