Access content of imported files in list box in VB.NET RRS feed

  • Question

  • Hello guys.

    I am making some kind of Simple Music Application software in VB.NET. Until now i am fine, but i need something more extreme than i have right now. 

    My Idea:

    I have a list box in When the user click the "Browse" button. He will be able to select a folder that contains music inside. Then will show all the folder's content in the list. Then the user can listen music by just clicking the name of the music he likes.


    I can import the folder's content inside the list box, but how i make the program NOT to open the music file using Windows Media Player etc. But play the sound as background. EX: My.Computer.Audio.Play(musicPath, AudioPlayMode.BackgroundLoop).

    Well if there is a simple code that will be able to play sound it will be great. 

    My code until now is:

       Dim di As New IO.DirectoryInfo("C:\Music")
            Dim diar1 As IO.FileInfo() = di.GetFiles()
            Dim dra As IO.FileInfo

            'list the names of all files in the specified directory
            For Each dra In diar1

    I haven't made it, so the user can identify the folder by it self. For now i am using a specific location! 

    Any help will be great!

    Thank you!!!!!

    Wednesday, August 29, 2012 4:33 PM


All replies

  • Hi,

    store the folder's path in a class-wide variable; add the Names of the files to the listbox (in your loop: musiclist.Items.Add(dra.Name)); in the SelectedIndeChanged event of the Listbox combine the folder's path with the fileName to get the FullPath to the file []; play that file as you want to - I prefer the mcisendstring function [



    Wednesday, August 29, 2012 5:08 PM
  • Dear, Thorsten Gudera

    Thank you very much for your quick reply. I am going to take a look on your helpful tips and i will reply to you in the next few days. Thank you very much!!!!!!

    Thursday, August 30, 2012 11:55 AM
  • Hi there.

    Well i have already done most of my coding. Thank you very much for your tip Thorsten Gudera.

    Well i have 2 serious problems. When i let the user pick their own folder's destination either by using "Open File Dialog" or "Open Folder Dialog". When i run my program through the VB application, and i click on the "Browse" button which has the "Open File Dialog" coding, it crashes and says: "VSHOST has stopped" something like that. When i Build my app and the run it, it won't show me the VSHOST error, but different kind of error. Anyway now i solved this by an inputbox which asks the folder's location. So the user will manually copy the folder's location inside the inputbox. Then the listbox shows all the audio that is located in the folder. When the user click on the play button. The software combines the folder's path, the files name and the files format giving output something like that: EX: "C:\\Music\audio.mp3". Normally the application should play the audio file, but unfortunately it gives an error saying that the audio file is not a vaild wave file. What to do next???

    the code to play the audio is: 

    My.Computer.Audio.Play(musicpath, AudioPlayMode.Background)

    I have checked the music path and it is vaild. Even if i replace the "Musicpath" in the code with the files path EX: "c:\\Music\audio.mp3". It won't play the file, and it will give an error.

    Thank you very much   

    Thursday, August 30, 2012 1:12 PM
  • ...

    the code to play the audio is: 

    My.Computer.Audio.Play(musicpath, AudioPlayMode.Background)



    My.Computer.Audio.Play plays only .wav files (just like the SoundPlayer class of .net). To play different soundfile types use a different way to play them.

    See the links to mcisendstring above, or use directX or a MediaPlayer:



    Thursday, August 30, 2012 1:33 PM
  • Thank you very much for your help Thorsten Gudera.

    I think i have found the solution. I have to use Windows Media Player in my project, but i have problem with my ActiveX Control which won't let me add "Windows Media Player" into my project. I tried installing some components that i found over the internet and my hole project crashed. It was a great project with long Coding and now i can't access it. It says that the editor doesn't exist. Hopefully i had an backup project that i could access! Until now, i haven't managed to play other Audio Files like .wav. But when i will, i will tell you how i did.

    Thank you very much for your Help!!!!! :)

    Friday, August 31, 2012 12:00 PM
  • Hi Andrikos,

    Welcome to the MSDN Forum.

    To play .wav file, Thorsten's suggestion: 

    My.Computer.Audio.Play plays only .wav files

    Will be helpful.

    Best regards,

    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 6, 2012 6:02 AM