Friday, December 10, 2010

Create mp3 player VB.Net2008

Creating a Mp3 Player In VB.net 2008 (Express \ Standard)
Aug 16
A Mp3 player is a hard task, but if you plan to use the Windows Media Player Controls it becomes so much easier, and so much quicker. In this tutorial I shall show you how to build your own basic Mp3 Player. Of course this is not going to oust great clients such as Winamp and Foobar2000, but it’s a good way to get to know using custom COM elements.
Ok let’s get started before I get to sleepy! Open up VB.net (Express Edition is fine) and now click File – New Project. In the new window that shows click Windows Form Application and type the project name to be Mp3Player


Click OK. Now in the toolbox (if the toolbox is not showing go to View – Toolbox) right click and select Choose Items from the right click menu. In the new ‘Choose Toolbox Items’ window that shows click the COM Components tab and then scroll down until you find the ‘Windows Media Player’ Control. Click the tickbox next to the name of the control

Click OK. Now in the general section of your Toolbox you should have a element called ‘Windows Media Player’ Drag this element onto your application. Depending on your Windows Media Player version you should get something that looks like the below image

Now to make things easier for creating your application move the element to the bottom of your application. Because the user won’t see the media player it’s not important about the size of location. It’s at this point you might find it nicer to slightly enlarge the application window (you can do this by clicking on one of the corners of the application and dragging it out). We now need to add a listbox. This will be our playlist editor, where the user will be able to add songs to play. You can add a listbox from the toolbox common controls area. Give this listbox full width of your application and leave above 15\20% at the top of your app. Make sure the listbox is selected then in the right hand (default position) properties section rename the listbox to ‘playlist’. In the properties section Anchor to Top, Left, Bottom and Right!

Your application should some what like the above image by this stage. We now need to allow the user to import files to the listbox. This is probably the most complex code of a mp3 player, and still it’s still rather basic code! Drag a button (from toolbox – Common controls) onto your application. Give this button a name of import and a text value in the properties to ‘Import’. You should also Anchor this button to Top, Right. Now once again from the toolbox drag OpenFileDialog from the Dialogs section. Don’t worry nothing will show up on your main application but you will see something like what shows below.

Click this button once to bring up the properties in the right menu for the dialog. Rename it importdiag and change the value multiselect to true. In the filter section of the properties for importdiag type the following:
Mp3 Music|*.mp3
The above will make sure the user can only select Mp3 files. Now double click on the ‘Import’ button you created earlier. This should take you into code view. Make sure your mouse cursor is within the Private Sub import_click and then type
importdiag.ShowDialog()
This will in turn show a open file window that Windows will generate for us. It will only show if the user has clicked the import button. Making sure you still have the importdiag button still clicked on the right properties menu click the small lightning bolt. You should now see something somewhat like the below image.

Double click on the item ‘FileOk’ (The actual text that says FileOK). You should now be in code view. Making sure your mouse is within the Private Sub importdiag_FileOk section, type the following code
For Each track As String In importdiag.FileNames
playlist.Items.Add(track)
Next
This code does the following: It goes though each one of the files the user selected and then adds it to our listbox. Because we’re only trying to create a simple Mp3 player we have not checked if the user is importing a valid filetype, but instead relying on the File Import window working in filtering to show on Mp3 tracks. Ok you can now test out importing Mp3 files. Press F5 to start debugging. Try important a collection of Mp3 files.
Now lets start to play these tracks! Add a button on your application and name it ‘play’, give it a text value of “Play”. Double click on this play button to enter the code view. Making sure your cursor is contained within Private Sub play_Click section type the following
AxWindowsMediaPlayer1.URL = playlist.SelectedItem
This calls our Windows media player item we added at the very start of the tutorial, and plays the selected item in the playlist. Add a new button to the application, this time call it stopbutton and have a text value of ‘Stop’. Double click the stop button and type the following code:
AxWindowsMediaPlayer1.Ctlcontrols.stop()
Once again add another button and this time call it pause with a text value of Pause. Double click it and in the code view type:
AxWindowsMediaPlayer1.Ctlcontrols.pause()
You can now open Mp3 files, play them, stop them and pause them. That’s it for this tutorial but on request I will go into more details with things such as track lengths, video playback and design. Let me know in the comments if you’d like that! I’d love to hear all your feedback! I’m off to bed now, I’m getting very sleepy!





Code 1:

Ingredients: 2 track bar(volume and trackposition)
1 progress bar(trackposition1)
5 buttons(but_next, play, back ,pause and stop)
4 labels
listview(tracklist and 1 colum named trackcol)
1 menustrip and create 8 downstrip(play, pause, fast forward, next, stop, volume up, volume down, exit

Public Class Media_Player
#Region "Color Settings"
Dim CurrentTrackColor As System.Drawing.Color = Color.Red
Dim PausedTrackColor As System.Drawing.Color = Color.LightYellow
#End Region
' Dim opendrive As WMPLib.WindowsMediaPlayer
' Dim i As Integer
' Dim total As Integer
Dim WithEvents vplayer As New AxWIAVIEWLib.AxVideoPreview
Dim WithEvents Player As New WMPLib.WindowsMediaPlayer
Dim files As Collections.ObjectModel.ReadOnlyCollection(Of String)
Dim titles As New List(Of String)
Dim CurrentPlaying As Integer = 0
Dim PreviouslyPlaying As Integer = 0
Private Sub but_Play_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_Play.Click
GUIMode("Play")
updatePlayer()
Player.controls.play()

End Sub

Private Sub but_Pause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_Pause.Click

If Player.playState = WMPLib.WMPPlayState.wmppsPaused Then
GUIMode("Play")
Else
GUIMode("Paused")
End If
End Sub

Private Sub but_Stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_Stop.Click
Player.controls.stop()
GUIMode("Stopped")
End Sub

Private Sub Volume_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Volume.Scroll
Player.settings.volume = Volume.Value
Label3.Text = Volume.Visible
End Sub

Private Sub TrackPosition_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackPosition.Scroll
Player.controls.pause()
Player.controls.currentPosition = ProgressBar1.Value
'Label9.Text = Player.controls.currentPosition
Player.controls.currentPosition = TrackPosition.Value
Player.controls.play()
updatePlayer()
' Allow the app to do some processing
Application.DoEvents()
End Sub

Private Sub Media_Player_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Player = Nothing
End Sub

Private Sub Media_Player_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Player.close()
End Sub

Private Sub Media_Player_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label7.Text = "Created By Mangciphu Zola"
'Me.BackgroundImage.Clone()
Randomize()
' Me.Label3.Text = ShowInTaskbar
Label5.Text = Player.versionInfo
Label2.Text = TrackList.Items.Count
'ShowInTaskbar = Me.Label3.Text
Player.windowlessVideo = True
but_Pause.Enabled = True
but_Stop.Enabled = True
'hide the progress bar which display the track position
ProgressBar1.Visible = False
Label10.Text = Player.controls.currentPosition
'set the place where you want this player to get them automatic
files = FileIO.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.Desktop, FileIO.SearchOption.SearchAllSubDirectories, "*.mp3")
files = FileIO.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.MyPictures, FileIO.SearchOption.SearchAllSubDirectories, "*.mp3")
files = FileIO.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData, FileIO.SearchOption.SearchAllSubDirectories, "*.mp3")
files = FileIO.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.MyMusic, FileIO.SearchOption.SearchAllSubDirectories, "*.mp3", "*.wav", "*.mp4", "*.avi", "*.MPEG")
For Each a As String In files
Me.TrackList.Items.Add(FileIO.FileSystem.GetName(a))
Next
Volume.Value = Player.settings.volume

'Me.txt_TrackName.Text = Player.URL

Player.settings.autoStart = False
Player.URL = files(0)
Player.enableContextMenu = False

Me.Text = ScrollStateVScrollVisible
With (Me.Timer1.Interval = 500)
Timer1.Start()
Enabled = True
End With
End Sub
Private Sub GUIMode(ByRef Guimode As String)
Select Case Guimode
Case ("Play")
' Put GUI in playing mode guise
Player.controls.play()
but_Pause.BackColor = System.Drawing.SystemColors.Control
but_Pause.Enabled = True
but_Stop.Enabled = True
Label4.Text = Player.status
but_Play.Enabled = True
Case ("Paused") ' put gui in paused mode guise
but_Pause.Enabled = True
but_Stop.Enabled = False
but_Play.Enabled = False
but_Pause.BackColor = PausedTrackColor
Player.controls.pause()
Case ("Stopped")
but_Pause.Enabled = False
but_Stop.Enabled = False

End Select

End Sub

Private Sub Player_MediaError(ByVal pMediaObject As Object) Handles Player.MediaError
MessageBox.Show("Unrecoverable Problem. Shutting Down", "MyMusic Player")
Me.Close()
End Sub

Private Sub Player_PlayStateChange(ByVal NewState As Integer) Handles Player.PlayStateChange
Static Dim PlayAllowed As Boolean = True
Select Case CType(NewState, WMPLib.WMPPlayState)
Case (WMPLib.WMPPlayState.wmppsReady)
If PlayAllowed Then
Player.controls.play()
End If
Case (WMPLib.WMPPlayState.wmppsMediaEnded)
' Reach end of track move onto next, looping around
PreviouslyPlaying = CurrentPlaying
CurrentPlaying = (CurrentPlaying + 1) Mod files.Count
' Start protection (without it next wouldn't play
PlayAllowed = False
' Play track
Player.URL = files(CurrentPlaying)
Player.controls.play()
' End Protection
PlayAllowed = True
updatePlayer()
End Select
Label4.Text = Player.status
Label10.Text = Player.controls.currentPosition.ToString
End Sub

Private Sub updatePlayer()
' Display track name
'txt_TrackName.Text = Player.currentMedia.name
' Label8.Text = Player.currentMedia.name
' ShowInTaskbar = Label3.Text
'Label3.Text = ShowInTaskbar
' txt_TrackArtist.Text = Player.status
' Update TrackPostion
With (ProgressBar1)
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = Val(Player.currentMedia.duration)
ProgressBar1.Value = Val(Player.controls.currentPosition())
End With
With (TrackPosition)
TrackPosition.Minimum = 0
TrackPosition.Maximum = CInt(Player.currentMedia.duration)
TrackPosition.Value = CInt(Player.controls.currentPosition())
End With
' Display Current Time Position and Duration
'txt_Progress.Text = Player.controls.currentPositionString & vbTab & Player.currentMedia.durationString
'Label4.Text = txt_Progress.Text = Player.controls.currentPositionString & vbTab & Player.currentMedia.durationString
' Set Volume slide to match current volume
Volume.Value = Player.settings.volume
' Is the CurrentPlaying Track No. is different to the Previous Track number.
If CurrentPlaying <> PreviouslyPlaying Then
' Yes,
' Set the forecolor of the corrisponding track, assiociated with the previous playing track, with the control color
TrackList.Items(PreviouslyPlaying).ForeColor = System.Drawing.SystemColors.ControlText
End If
' Set the forecolor of the corrisponding track, assiociated with the currently playing track, with the current track color
TrackList.Items(CurrentPlaying).ForeColor = CurrentTrackColor
Label4.Text = Player.status
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

' MessageBox.Show("Are You Sure About that? and the playing track is ...", Me.Text, MessageBoxButtons.YesNo)
Label4.Text = Player.status
' Me.Text = ScrollStateAutoScrolling
'ProgressBar1.Style = Me.Text
' Label4.Text = ShowInTaskbar.ToString
' Player.controls.currentItem.name = ShowInTaskbar
'it displays the playing track on the taskbar
Me.Text = Player.controls.currentItem.name & " " & Label10.Text
SetScrollState(8, True)
'this shows the total time of a track
Label9.Text = Player.controls.currentItem.durationString
'the current time of a track
Label10.Text = Player.controls.currentPositionString
' Label11.Text =
Label3.Text = Volume.Value.ToString & "%"
REM Label11.Text = Player.controls.currentItem.attributeCount
updatePlayer()
Label1.Text = DateAndTime.Now
End Sub

Private Sub TrackList_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
GUIMode("Play")
Randomize()
' A track in the tracklisting has been double clicked on
PreviouslyPlaying = CurrentPlaying
' Set CurrentPlaying to position of selected track.
CurrentPlaying = TrackList.SelectedIndices(0)
' Play the track
Player.URL = files(CurrentPlaying)
updatePlayer()
Player.controls.play()
End Sub


Private Sub MuteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MuteToolStripMenuItem.Click
Player.settings.mute = True
End Sub

Private Sub PlayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayToolStripMenuItem.Click
GUIMode("Play")
updatePlayer()
Player.controls.play()
Label10.Text = Player.controls.currentPosition.ToString
End Sub

Private Sub but_Next_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_Next.Click
Randomize()
' A track in the tracklisting has been double clicked on
PreviouslyPlaying = CurrentPlaying
' Set CurrentPlaying to position of selected track.

' Play the track
Player.URL = files(CurrentPlaying)
updatePlayer()
Player.controls.play()

GUIMode("next")
updatePlayer()
CurrentPlaying = CurrentPlaying + 1


Player.controls.next()
Player.controls.play()

End Sub

Private Sub StopToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopToolStripMenuItem.Click
Player.controls.stop()
GUIMode("Stopped")
End Sub

Private Sub PauseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PauseToolStripMenuItem.Click
If Player.playState = WMPLib.WMPPlayState.wmppsPaused Then
GUIMode("Play")
Else
GUIMode("Paused")
End If
End Sub

Private Sub FastForwardToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FastForwardToolStripMenuItem.Click
Player.controls.fastForward()

End Sub

Private Sub FastRewindToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FastRewindToolStripMenuItem.Click
Player.controls.fastReverse()
End Sub

Private Sub but_Back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_Back.Click
Randomize()
' A track in the tracklisting has been double clicked on
PreviouslyPlaying = CurrentPlaying
' Set CurrentPlaying to position of selected track.

' Play the track
Player.URL = files(CurrentPlaying)
updatePlayer()
Player.controls.play()

GUIMode("back")
updatePlayer()
CurrentPlaying = CurrentPlaying - 1


Player.controls.previous()
Player.controls.play()

End Sub

Private Sub RedToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedToolStripMenuItem.Click

Me.BackColor = Color.Red
End Sub

Private Sub ShowAdvanceSeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowAdvanceSeToolStripMenuItem.Click
TrackPosition.Visible = False
ProgressBar1.Visible = True
End Sub

Private Sub NormalSeekToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NormalSeekToolStripMenuItem.Click
TrackPosition.Visible = True
ProgressBar1.Visible = False
End Sub
Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBar1.Click
Player.controls.play()
updatePlayer()
' Allow the app to do some processing
Application.DoEvents()
End Sub



Private Sub TrackList_DoubleClick1(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackList.DoubleClick
GUIMode("Play")
Randomize()
' A track in the tracklisting has been double clicked on
PreviouslyPlaying = CurrentPlaying
' Set CurrentPlaying to position of selected track.
CurrentPlaying = TrackList.SelectedIndices(0)
' Play the track
Player.URL = files(CurrentPlaying)
updatePlayer()
Player.controls.play()
End Sub


Private Sub NextToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextToolStripMenuItem.Click
Randomize()
' A track in the tracklisting has been double clicked on
PreviouslyPlaying = CurrentPlaying
' Set CurrentPlaying to position of selected track.

' Play the track
Player.URL = files(CurrentPlaying)
updatePlayer()
Player.controls.play()

GUIMode("next")
updatePlayer()
CurrentPlaying = CurrentPlaying + 1


Player.controls.next()
Player.controls.play()
End Sub

Private Sub BackToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackToolStripMenuItem.Click
Randomize()
' A track in the tracklisting has been double clicked on
PreviouslyPlaying = CurrentPlaying
' Set CurrentPlaying to position of selected track.

' Play the track
Player.URL = files(CurrentPlaying)
updatePlayer()
Player.controls.play()

GUIMode("back")
updatePlayer()
CurrentPlaying = CurrentPlaying - 1


Player.controls.previous()
Player.controls.play()

End Sub

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



Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
Player.settings.volume = Volume.Value + 1
End Sub

Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem3.Click
Player.settings.volume = Volume.Value + 2
End Sub

Private Sub ToolStripMenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem4.Click
Player.settings.volume = Volume.Value + 5
End Sub

Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem5.Click
Player.settings.volume = Volume.Value + 10
End Sub

Private Sub ToolStripMenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem6.Click
Player.settings.volume = Volume.Value + 20
End Sub

Private Sub ToolStripMenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem7.Click
Player.settings.volume = Volume.Value + 50
End Sub

Private Sub ToolStripMenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem8.Click
Player.settings.volume = Volume.Value - 1
End Sub

Private Sub ToolStripMenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem9.Click
Player.settings.volume = Volume.Value - 2
End Sub

Private Sub ToolStripMenuItem10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem10.Click
Player.settings.volume = Volume.Value - 5
End Sub

Private Sub ToolStripMenuItem11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem11.Click
Player.settings.volume = Volume.Value - 10
End Sub

Private Sub ToolStripMenuItem12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem12.Click
Player.settings.volume = Volume.Value - 20
End Sub

Private Sub ToolStripMenuItem13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem13.Click
Player.settings.volume = Volume.Value - 50
End Sub

Private Sub ShuffleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShuffleToolStripMenuItem.Click
Randomize()
' A track in the tracklisting has been double clicked on
PreviouslyPlaying = CurrentPlaying
' Set CurrentPlaying to position of selected track.

' Play the track
Player.URL = files(CurrentPlaying)
updatePlayer()
Player.controls.play()

GUIMode("Random")
updatePlayer()
For i = 0 To CurrentPlaying
CurrentPlaying = Rnd(CurrentPlaying + 1)
updatePlayer()
Next
Player.controls.previous()
Player.controls.play()
End Sub

Private Sub GreenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GreenToolStripMenuItem.Click
Me.BackColor = Color.Green
End Sub

Private Sub YellowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YellowToolStripMenuItem.Click
Me.BackColor = Color.Yellow
End Sub

Private Sub IndigoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IndigoToolStripMenuItem.Click
Me.BackColor = Color.Indigo
End Sub

Private Sub MaroonToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MaroonToolStripMenuItem.Click
Me.BackColor = Color.Maroon
End Sub

Private Sub PinkToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PinkToolStripMenuItem.Click
Me.BackColor = Color.Pink
End Sub

Private Sub LightBlueToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LightBlueToolStripMenuItem.Click
Me.BackColor = Color.LightBlue
End Sub

Private Sub DefaultToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DefaultToolStripMenuItem.Click
Me.BackColor = Color.Empty
End Sub
End Class




Code2:
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class UseMediaPlayer
public Shared Sub Main
Application.Run(New FrmMediaPlayer)
End Sub
End class

Public Class FrmMediaPlayer
Inherits System.Windows.Forms.Form

' action menus
Friend WithEvents applicationMenu As MainMenu
Friend WithEvents fileItem As MenuItem
Friend WithEvents openItem As MenuItem
Friend WithEvents exitItem As MenuItem
Friend WithEvents aboutItem As MenuItem
Friend WithEvents aboutMessageItem As MenuItem

' media player control
Friend WithEvents player As AxMediaPlayer.AxMediaPlayer
Friend WithEvents openMediaFileDialog As OpenFileDialog

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FrmMediaPlayer))
Me.applicationMenu = New System.Windows.Forms.MainMenu()
Me.fileItem = New System.Windows.Forms.MenuItem()
Me.openItem = New System.Windows.Forms.MenuItem()
Me.exitItem = New System.Windows.Forms.MenuItem()
Me.aboutItem = New System.Windows.Forms.MenuItem()
Me.aboutMessageItem = New System.Windows.Forms.MenuItem()
Me.openMediaFileDialog = New System.Windows.Forms.OpenFileDialog()
Me.player = New AxMediaPlayer.AxMediaPlayer()
CType(Me.player, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'applicationMenu
'
Me.applicationMenu.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.fileItem, Me.aboutItem})
'
'fileItem
'
Me.fileItem.Index = 0
Me.fileItem.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.openItem, Me.exitItem})
Me.fileItem.Text = "File"
'
'openItem
'
Me.openItem.Index = 0
Me.openItem.Text = "Open"
'
'exitItem
'
Me.exitItem.Index = 1
Me.exitItem.Text = "Exit"
'
'aboutItem
'
Me.aboutItem.Index = 1
Me.aboutItem.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.aboutMessageItem})
Me.aboutItem.Text = "About"
'
'aboutMessageItem
'
Me.aboutMessageItem.Index = 0
Me.aboutMessageItem.Text = "About Windows Media Player"
'
'player
'
Me.player.Name = "player"
Me.player.OcxState = CType(resources.GetObject("player.OcxState"), System.Windows.Forms.AxHost.State)
Me.player.Size = New System.Drawing.Size(312, 288)
Me.player.TabIndex = 0
'
'FrmMediaPlayer
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(312, 287)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.player})
Me.Menu = Me.applicationMenu
Me.Name = "FrmMediaPlayer"
Me.Text = "MediaPlayer"
CType(Me.player, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub openItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles openItem.Click

openMediaFileDialog.ShowDialog()

player.FileName = openMediaFileDialog.FileName

player.Size = New Size(player.ImageSourceWidth, player.ImageSourceHeight)

Me.Size = New Size(player.Size.Width + 20,player.Size.Height + 60)
End Sub ' openItem_Click

' exit application
Private Sub exitItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles exitItem.Click

Application.Exit()
End Sub ' exitItem_Click

Private Sub aboutMessageItem_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles aboutMessageItem.Click

player.AboutBox()
End Sub

End Class

No comments:

Post a Comment

social media buttons