我正在寻找一个简单的C#解决方案来管理播放列表。不是实际的播放功能,只需添加,删除,重新排序等等。
这些代码是否存在?
答案 0 :(得分:1)
假设您的播放列表中包含以下内容:
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;
等...
如果您愿意,您甚至可以将List<T>
子类添加自己的信息,例如当前播放的歌曲:
public class Playlist : List<PlaylistItem> {
public Int32 CurrentSong { get; set; }
}