Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys

I was trying to code a simple word quizz application for my students, with 20 years old and extremely rusty coding knowledge. But the more I coded, the more stuff I aspired to add my application. In the end, I found myself trying to list mp3 files for pronounciation purposes and trying to use WMPLib to let them listen to some educational songs. This was not intended but once you start, it's hard to refrain.

So I am having a series of problems with this process.

1- I am trying to populate a combobox with the mp3 files. My problem is, combobox also sees the albumart, folder.art or any kind of embedded or hidden files that are actually not in that folder. If there is an mp3 file with an embedded album art, that is also added to the combobox as an item, naturally not only results in an ugly list but also crashes the player unless I put a handler.

2- The method I used might be amateur, or plainly wrong. But I couldn't imagine how to show the player the file from a combobox, because I used getfilenames method to prevent long and ugly names in the combobox list. So I used an arraylist and matched the indexes of the combobox with the arrarlist indexes. So I keep the directory path in the array list, pick the mp3 file from the combobox then compare the indexes and get the path from the arraylist item with the same index. Yeah I can hear you, it sounds dumb but also was the only method I could really consider. If there is a more elegant way, please let me know.

Can anyone help me to get an idea about these?

Thanks in advance

<pre>
Public Class frmPlayer
    Dim list As ArrayList
    Dim Player As WindowsMediaPlayer = New WindowsMediaPlayer

    Private Sub FrmPlayer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim cb As ComboBox = New ComboBox
        list = New ArrayList

        For Each s As String In System.IO.Directory.GetFiles(Application.StartupPath & "\music\")
            cb.Items.Add(s)
            list.Add(s)
            ComboBox1.Items.Add(IO.Path.GetFileName(s))
        Next
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'Player = New WindowsMediaPlayer


        If Player.playState = WMPPlayState.wmppsPlaying Then
            Player.URL = Player.currentMedia.name
            Player.controls.stop()
        Else
            Player.URL = list.Item(ComboBox1.SelectedIndex)
            Player.controls.play()
        End If


    End Sub
End Class


What I have tried:

I tried linq method to pick only mp3 files but it got things much more complicated as I am using both an arraylist and a combobox.
Posted
Updated 26-Dec-20 20:22pm
v2

1 solution

You can narrow your selection with GetFiles() itself:

c# - Can you call Directory.GetFiles() with multiple filters? - Stack Overflow[^]
 
Share this answer
 
Comments
salim çataloglu 27-Dec-20 6:56am    
Well I don't know c# well, but chances are that code will work in vb.net too. If it works, it solves my problem shortly, with only 1 line of code. I will try and give feedback.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900