我在为下面的代码添加随机播放时遇到问题。有人可以帮我吗?我所需要的只是在添加项目后随机洗牌playlist
项目。
WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(
@"C:UsersCallumMusicItunesMusic");
System.IO.FileInfo[] files = dir.GetFiles();
WMPLib.IWMPPlaylist playlist = wplayer.playlistCollection.newPlaylist("myplaylist");
foreach (System.IO.FileInfo file in files)
{
WMPLib.IWMPMedia media;
media = wplayer.newMedia(file.FullName);
playlist.appendItem(media);
}
wplayer.currentPlaylist = playlist;
wplayer.controls.play();
您需要告诉播放器在播放播放列表之前随机播放:
wplayer.currentPlaylist = playlist;
wplayer.settings.setMode("shuffle", true); // this does the trick
wplayer.controls.play();