Wednesday, April 10, 2013

How to make a media player

How to make a media player

First create a new project in visual studio and give it a name. Here I given Advanced Media Player. Then you have to drag and drop components as in the fallowing figure.



The menu item bar contains three tags called File, Media, Help. In each item tag contains sub item tags as fallows.

* File








* Media












* Help






Then you have to code to the each button and also menu bar items as fallows.


Public Class MediaPlayerForm

Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

End Sub

Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
OpenFileDialog1.ShowDialog()
' AxWindowsMediaPlayer1.URL = OpenFileDialog1.FileName

End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub

Private Sub NextToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextToolStripMenuItem.Click
AxWindowsMediaPlayer1.Ctlcontrols.next()
End Sub

Private Sub PreviousToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PreviousToolStripMenuItem.Click
AxWindowsMediaPlayer1.Ctlcontrols.previous()
End Sub

Private Sub PauseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PauseToolStripMenuItem.Click
AxWindowsMediaPlayer1.Ctlcontrols.pause()
End Sub

Private Sub StopToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopToolStripMenuItem.Click
AxWindowsMediaPlayer1.Ctlcontrols.stop()
End Sub

Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
Me.Close()
End Sub

Private Sub PlayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayToolStripMenuItem.Click
AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub

Private Sub AboutMediaPlayerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutMediaPlayerToolStripMenuItem.Click
AboutBox1.Show()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AxWindowsMediaPlayer1.Ctlcontrols.previous()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
AxWindowsMediaPlayer1.Ctlcontrols.stop()
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
AxWindowsMediaPlayer1.Ctlcontrols.pause()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
AxWindowsMediaPlayer1.Ctlcontrols.next()
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
OpenFileDialog1.ShowDialog()
'AxWindowsMediaPlayer1.URL = OpenFileDialog1.FileName
End Sub

Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
AxWindowsMediaPlayer1.settings.volume = TrackBar1.Value
End Sub

Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
'For Each track As String In OpenFileDialog1.FileName
ListBox1.Items.Add(OpenFileDialog1.FileName)
' Next
End Sub

Private Sub ClearPlaylistToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearPlaylistToolStripMenuItem.Click
ListBox1.Items.Clear()
End Sub

End Class




Final output

The final output can obtain like this.