-1

I'm looking for a simple C# solution to manage a playlist. Not the actual playback functionality, just adding, removing, reordering stuff and so on.

Does such code exist?

3
  • In general, or for windows media player or for flash or what?
    – Telastyn
    Apr 9, 2012 at 14:35
  • It's going to be a custom WinForms player, but I think it doesn't make any difference. Any general solution should be fine. Apr 9, 2012 at 14:54
  • What are your constraints on what it needs to do? Is it a fixed playlist that loops (or doesn't)? Is there some algorithm that needs to determine what to include or play next?
    – Telastyn
    Apr 9, 2012 at 15:04

1 Answer 1

1

Assuming that your playlist has items like this in it:

public class PlaylistItem { 
    public String Artist { get; set; }
    public String Album { get; set; }
    public String Song { get; set; }
    public TimeSpan Length { get; set; }
    public String SongFile { get; set; }
}

Then a List<PlaylistItem> should do:

var mySong = new PlayListItem { 
    Artist = "LMFAO", 
    Album = "Sorry for Party Rocking", 
    Song = "Sexy and I Know It", 
    Length = new TimeSpan(0,0,0,0,3,19,0), 
    SongFile = "C:\LMFAO.mp3" };
var myPlaylist = new List<PlaylistItem>();

// Add an item:
myPlayList.Add(mySong);

// Remove an item:
myPlayList.Remove(mySong);

// Reorder (assuming you've added some other items):
var song = myPlayList[0];
myPlayList[0] = myPlayList[1];
myPlayList[1] = song;

etc...

If you want, you can even subclass List<T> to add your own information, like which song is currently playing:

public class Playlist : List<PlaylistItem> {
    public Int32 CurrentSong { get; set; }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.