将shuffle添加到WMPlib播放列表

时间:2015-03-11 21:08:10

标签: c# media-player shuffle

我无法在下面的代码中添加随机播放。有人可以帮帮我吗?我只需要在playlist添加项目之后随机随机播放这些项目。

WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(
    @"C:\Users\Callum\Music\ItunesMusic\");

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();

1 个答案:

答案 0 :(得分:1)

在播放播放列表之前,您需要告诉播放器进行随机播放:

wplayer.currentPlaylist = playlist;
wplayer.settings.setMode("shuffle", true); // this does the trick
wplayer.controls.play();