Results 1 to 9 of 9

Thread: [2005] Need help with the openfiledialog and listview in my mp3 player

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    115

    Question [2005] Need help with the openfiledialog and listview in my mp3 player

    Right now i'm working on a mp3 player so to be full media player but I need help with the listview. I can open the music files i select and they appear in the listview and they play using MCI. My problem is I only want it split to show only the song in the listview not the directory that it came from. Here's my code for the openfiledialog:

    VB Code:
    1. Dim theList As Collection = New Collection()
    2.  
    3.         Dim x As Integer = Nothing
    4.         OFD.Title = "Select music file"
    5.         OFD.Multiselect = True
    6.         OFD.Filter = "MP3 files (*.m3u, *.mp3, *.wav, *.wma, *.cda)|*.m3u;*.mp3;*.wav;*.wma;*.cda|Playlist (*.m3u)|*.m3u|MP3 files (*.mp3)|*.mp3|WAV files (*.wav)|*.wav|WMA files (*.wma)|*.wma|CDA files (*.cda)|*.cda|All files (*.*)|*.*"
    7.  
    8.         If (OFD.ShowDialog() = Windows.Forms.DialogResult.OK) Then
    9.             lstSongs.Items.Clear()
    10.  
    11.             For Each filename As String In OFD.FileNames
    12.                 If filename.EndsWith(".mp3") Then
    13.                     lstSongs.Visible = True
    14.                     lblList.Text = "Hide List"
    15.                     Dim ttext As String
    16.  
    17.                     ttext = Trim(filename)
    18.                     'If lstSongs.Items.Contains(ttext) = True Then
    19.  
    20.                     lstSongs.Items.Add(ttext)
    21.  
    22.                 ElseIf filename.EndsWith(".wma") Then
    23.                     lstSongs.Visible = True
    24.                     lblList.Text = "Hide List"
    25.                     Dim ttext As String
    26.  
    27.                     ttext = Trim(filename)
    28.                     'If lstSongs.Items.Contains(ttext) = True Then
    29.  
    30.                     lstSongs.Items.Add(ttext)
    31.  
    32.                 ElseIf filename.EndsWith(".wav") Then
    33.                     lstSongs.Visible = True
    34.                     lblList.Text = "Hide List"
    35.                     Dim ttext As String
    36.  
    37.                     ttext = Trim(filename)
    38.                     'If lstSongs.Items.Contains(ttext) = True Then
    39.  
    40.                     lstSongs.Items.Add(ttext)
    41.  
    42.                 ElseIf filename.EndsWith(".cda") Then
    43.                     lstSongs.Visible = True
    44.                     lblList.Text = "Hide List"
    45.                     Dim ttext As String
    46.  
    47.                     ttext = Trim(filename)
    48.                     'If lstSongs.Items.Contains(ttext) = True Then
    49.  
    50.                     lstSongs.Items.Add(ttext)
    51.  
    52.                 ElseIf OFD.FileName.EndsWith(".m3u") Then
    53.  
    54.                     lstSongs.Items.Clear()
    55.  
    56.                     theList = Vmp3.openPlaylist(OFD.FileName)
    57.  
    58.  
    59.                     For x = 0 To theList.Count - 1
    60.  
    61.                         lstSongs.Items.Add(theList.Item(x + 1))
    62.  
    63.                     Next
    64.  
    65.  
    66.                     'lstSongs.Items.Add(OFD.FileName)
    67.                 End If
    68.             Next
    69.         End If

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Need help with the openfiledialog and listview in my mp3 player

    Hey!
    Sorry but I for one doesnt understand the question
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Addicted Member Gameunreal's Avatar
    Join Date
    Jun 2006
    Location
    gone fishing
    Posts
    249

    Re: [2005] Need help with the openfiledialog and listview in my mp3 player

    mmm... i dont either..
    -=PATRICK=-
    Using Visual Basic .NET 2005


    If you found a post useful then please Rate it!



    Hidden DOS secret: add BUGS=OFF to your CONFIG.SYS
    A program is a device used to convert data into error messages.
    Programmer's Drinking Song: 99 programming bugs in the code/99 programing bugs/Fix one bug/compile it again/now there's 100 bugs in the code! (repeat until bugs==0)
    All wiyht. Rho sritched mg kegtops awound?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    115

    Re: [2005] Need help with the openfiledialog and listview in my mp3 player

    ok for example I open up a .mp3 file to play and it shows up in the listview as c:\Music\random song\anysong.mp3 but I only want the anysong part to show up not the directory of it I need to split it I tried substring and indexof but didn't work

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    115

    Re: [2005] Need help with the openfiledialog and listview in my mp3 player

    also if my question still isn't makeing any sense I can get a screenshot and maybe explain it better that way because I need help with this

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Need help with the openfiledialog and listview in my mp3 player

    VB Code:
    1. Dim f As String = "c:\Music\random song\anysong.mp3"
    2.         MsgBox(f.Substring(f.LastIndexOf("\") + 1, f.Length - (f.LastIndexOf("\") + 5)))

    Like this?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    115

    Re: [2005] Need help with the openfiledialog and listview in my mp3 player

    well I finally got it working thanks Atheist your code put me on the right track this is how I fixed it

    VB Code:
    1. If (OFD.ShowDialog() = Windows.Forms.DialogResult.OK) Then
    2.             lstSongs.Items.Clear()
    3.  
    4.             For Each filename As String In OFD.FileNames
    5.                 If filename.EndsWith(".mp3") Then
    6.                     lstSongs.Visible = True
    7.                     lblList.Text = "Hide List"
    8.                     Dim s As String
    9.                     Dim s2 As String
    10.                     Dim sR As String
    11.                     s = filename
    12.                     sR = StrReverse(s)
    13.                     s2 = s.Substring(Len(s) - sR.IndexOf("\"))
    14.                     lstSongs.Items.Add(s2)
    Last edited by one_&_only; Aug 5th, 2006 at 08:10 PM.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Need help with the openfiledialog and listview in my mp3 player

    The Path class is provided specifically for manipulating file paths. If you want to get the file name from a path then you may not be surprised to hear that the Path.GetFileName method is the way to go:
    VB Code:
    1. lstSongs.Items.Add(IO.Path.GetFileName(ofd.FileName))
    The simple things in life are often the most overlooked.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    115

    Re: [2005] Need help with the openfiledialog and listview in my mp3 player

    thanks alot jmcilhinney I never even knew I could do it that way

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