#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    41
    Rep Power
    10

    Question How can i make a Playlist like WinAMP?


    Hi, i've been trying for a while to make a Playlist like the one in WinAMP, but i can, i only can do it to put all the files that i select in the opendialog in the listbox but it show me the full path of the file and i don't wanna, i want do is to show the number of the entry, the filename (without path) or song name and the lenght of the song, it is possible do that in Delphi?
    Please can somene help me please?

    Forgive me for my bad English!

    Thanks for you attention
    UltraMAX
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    You can extract the file name from the fullpath by using the ExtractFileName() function. As for the length of the song, you could perhaps get this information from the TMediaPlayer component (TrackLength property should do it).
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    41
    Rep Power
    10
    Thanlks for replying me Scorpions4ever, yes it's true, but when i save the playlist, how can i return the full path of the file, it save all files in the list without the path!!!
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    I'm pretty certain that TList has an Add(), as well as an AddObject() method. You can use AddObject() to add a string and its associated object. Thus, you can add just the file name and store the whole path name in the associated object. When you need to store it:
    Code:
    type
      TmyObject = TObject
         sPath : string
      end;
    
    procedure TForm1.AddToList(sFullPath : string;
    var
       obj : TmyObject;
       sFileName : string;
    begin
       sFileName := ExtractFileName(sFullPath);
       obj := TmyObject.Create;
       obj.sPath := sFullPath;
       list1.Items.AddObject(sFileName, TObject(obj));
    end;
    To retrieve the filename and filepath, you would do something like this:
    Code:
    procedure TForm1.GetItem(i : integer);
    var
       obj : TmyObject;
    begin
      sFileName = list1.Items.Strings[i];
      obj = list1.Items.Objects[i] as TmyObject;
      sFullPath = obj.sPath;
    end;
    Note that I don't have a Delphi compiler handy, so the above code is completely untested.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    41
    Rep Power
    10
    Thanks again Scorpions4ever you're a nice guy, man, i've got the same problem when i'm gonna save the list (List1.Items.SaveToFile), it saves the filename but the path it's "gone", but the rest it works great! Any clue please?
  10. #6
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    Guess you shouldn't do a savetofile directly then. Instead, you could tell it to save both the filename and the filepath, or just the filepath alone. You could do something like this:
    Code:
    var
       stl : TStringList;
       i : integer;
       obj: TMyObject;
       sFileName, sFilePath : string;
    begin
       stl := TStringList.Create;
       for i := 0 to List1.Items.Count - 1 do
       begin
           sFileName := List1.Items.Strings[i];
           obj := list1.Items.Objects[i] as TmyObject;
           sFilePath := obj.sPath;
           /* Add filename and filepath in two separate lines */
           stl.Add(sFileName);
           stl.Add(sFilePath);
       end;
       
       stl.SaveToFile('filename.txt');
       stl.Free;
    end;
    You could use similar code when reading the file back to reconstruct List1.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    41
    Rep Power
    10
    You could use similar code when reading the file back to reconstruct List1.
    Yes, i've tried that man, but when i go to read the file to play ... jesus .. where is the path, i can't play the file, only if i select a file or files and then double click on them to play, if i open a playlist, i can't ... anything else it's working allright man, thank you a lot, i'm keep trying if i can fix the problem.

    Thank you Scorpions4ever !

    UltraMAX

IMN logo majestic logo threadwatch logo seochat tools logo