我正在寻找一个简单的 C# 解决方案来管理播放列表。不是实际的播放功能,只是添加、删除、重新排序等等。
这样的代码存在吗?
假设您的播放列表中有这样的项目:
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; }
}
然后List<PlaylistItem>
应该做:
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...
如果您愿意,您甚至可以子类List<T>
化以添加您自己的信息,例如当前正在播放的歌曲:
public class Playlist : List<PlaylistItem> {
public Int32 CurrentSong { get; set; }
}