Results 1 to 2 of 2

Thread: Showing all music in a List box

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Posts
    92

    Showing all music in a List box

    I'm creating a Media Player with VB.Net 2003. I can browse out and select a song to play and it plays it, but I would like all my music in the "My Music" Folder to appear is a listbox. So i can select from there what song i want to play. Can anyone help me on how to do this? Here is the code I have right now:
    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
    Const DATA_FILE_EXTENSION As String = ".mp3"
    Dim dlgFileDialog As New OpenFileDialog
    With dlgFileDialog
    .Filter = DATA_FILE_EXTENSION & _
    " files (*" & DATA_FILE_EXTENSION & "|*" & DATA_FILE_EXTENSION
    .FilterIndex = 1
    .RestoreDirectory = True
    If .ShowDialog() = DialogResult.OK Then
    'Play the sound file
    Me.AxWindowsMediaPlayer1.URL = dlgFileDialog.FileName
    End If
    End With
    End Sub

  2. #2
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Re: Showing all music in a List box

    Try this:

    VB Code:
    1. Dim folderPath As String = "c:\NameOfFolder"
    2. Dim songList() As String = System.IO.Directory.GetFiles(folderPath, "*.mp3")
    3. ListBox1.DataSource = songList

    this should display all .mp3 files in the listbox.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width