title: How to track file names on a media player playlist and get current playing file index
body: <p>so I'm developing a music player based on Un4seen Bass audio library , It does everything correctly except for playlist management which I'm having difficulties to fix it , my playlist system works as following , I have a class called Playlist it contains all the functions for playlist management (adding , removing , tracking(here's the problem) ...etc), It contains a listbox as a playlist , and a timer responsible for tracking Zero-Based index of currently playing file on the Player Class on the Main Form , If i activate the no duplicates mode on the Playlist class it tracks the current playing file just fine and i can get the index correctly , but if i deactivate the no duplicates mode and assume i have (Let's call it Song1 for now) Song1 as the first file on the playlist and i have it also as the Tenth file on the playlist also. The playlist will feed the Player with filenames to start and since the <code>IndexOf</code> function of the playlist get's the first match on the list when it gets to the tenth file which is Song1 it will return to the first file on the list and start looping only those 9 songs , i tried using ` <code>LastIndexOf</code> but still not working correctly , i though of using Unique file names but i get file doesn't exist on <code>IO.File.Exists</code> , Can you guide me ?
  Here is my Code :</p>
  
  <pre><code>Private Sub IndexTimer_Tick(sender As Object, e As EventArgs) Handles IndexTimer.Tick
          Try
              If My.Forms.Form1.Visible = True Then
                  If My.Settings.Playlist_Tracking = My.Forms.Settings.PlaylistTracking.FirstIndex Then
                      Index = Playlist.Items.IndexOf(My.Forms.Form1.P1.sourceURL)
                  ElseIf My.Settings.Playlist_Tracking = My.Forms.Settings.PlaylistTracking.LastIndex Then
                      Index = Playlistalt.LastIndexOf(My.Forms.Form1.P1.sourceURL)
                  End If
              End If
          Catch ex As Exception
              Console.WriteLine(My.Computer.Clock.LocalTime.ToShortTimeString &amp; ": " &amp; ex.Message)
          End Try
      End Sub
  </code></pre>
  
  <p>PS : The <code>Playlistalt</code> is a <code>List(of string)</code> because <code>Listbox</code> doesn't have <code>LastIndexOf</code> methode
  <br>Also all of the solutions i found are using Windows Media Player , which i used but it's not enough for me
  <br>Thank you ^^</p>
  
  <p>Edit : The code for song adding sub</p>
  
  <pre><code>Public Sub Add(song As String)
          If IO.File.Exists(song) Then
              If My.Settings.Playlist_RemoveOnAdd = False AndAlso My.Settings.Playlist_Tracking &lt;&gt; My.Forms.Settings.PlaylistTracking.FirstIndexAdvanced Then
                  Playlist.Items.Add(song)
                  Playlistalt.Add(song)
              ElseIf My.Settings.Playlist_RemoveOnAdd = False AndAlso My.Settings.Playlist_Tracking = My.Forms.Settings.PlaylistTracking.FirstIndexAdvanced Then
                  Playlist.Items.Add(song)
                  Playlistalt.Add(song)
                  RemoveDuplicates(True)
              ElseIf My.Settings.Playlist_RemoveOnAdd = True AndAlso My.Settings.Playlist_Tracking &lt;&gt; My.Forms.Settings.PlaylistTracking.FirstIndexAdvanced Then
                  Playlist.Items.Clear()
                  Playlist.Items.Add(song)
                  Playlistalt.Clear()
                  Playlistalt.Add(song)
              ElseIf My.Settings.Playlist_RemoveOnAdd = True AndAlso My.Settings.Playlist_Tracking = My.Forms.Settings.PlaylistTracking.FirstIndexAdvanced Then
                  Playlist.Items.Clear()
                  Playlist.Items.Add(song)
                  Playlistalt.Clear()
                  Playlistalt.Add(song)
                  RemoveDuplicates(True)
              End If
              RaiseEvent PlaylistItemsChanged()
          Else
              Console.WriteLine(My.Computer.Clock.LocalTime.ToShortTimeString &amp; ": " &amp; "Please check if your file exists then add it to the playlist")
          End If
      End Sub```
  </code></pre>