Sunday, 18 December 2016

Creating a Media Playlist using Widows Media Player in VB.NET

1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.
2. Right click the ToolBox, and click the Choose Items.

3. Now, check the Windows Media Player in the COM components.

4. Next, add the WindowsMediaPlayer component to the Form and insert a button named Button1 to add song to the ListBox. Add also a LisBox named ListBox1 to view all the songs and an OpenFileDialog for the button. You must design your interface like this:

5. Then, let's code!
We will code for the button to open some files and be put on the LitBox.

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFileDialog1.ShowDialog()
        If Windows.Forms.DialogResult.OK Then
            For Each track As String In OpenFileDialog1.FileNames
                ListBox1.Items.Add(track)
            Next
        End If
Then, after putting the files on the ListBox, put this code below for playing the selected music or videos in the ListBox.
 Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
    End Sub

0 comments:

Post a Comment