Introduction
A screensaver consists of a form that can load from 1 to 16 Windows MediaPlayer
controls. Each MediaPlayer
control loads media files selected by the user,
stores them in a random playlist, and then plays all the media Files. It can play all Windows Media Player supported formats (video files, image files, music).
private void ScreenSaverForm_Load(object sender, System.EventArgs e)
{
Cursor.Hide();
TopMost = true;
string playlistName;
string playlistBase = "ABU Video ScreenSaver Playlist";
string[] selectedfiles = null;
if (this.ScreenSettings.FileToPlay != String.Empty)
selectedfiles = this.ScreenSettings.FileToPlay.Split(',');
string[] folderFiles =
this.GetFolderFiles(this.ScreenSettings.FolderToPlay);
int len = 0;
if (selectedfiles != null)
len += selectedfiles.Length;
if (folderFiles!=null)
len += folderFiles.Length;
string[] files = new string[len];
int startIndex = 0;
if (selectedfiles != null)
{
selectedfiles.CopyTo(files, startIndex);
startIndex = selectedfiles.Length;
}
if (folderFiles!=null)
folderFiles.CopyTo(files, startIndex);
string[] filesShuffled;
int cnt = 0;
foreach (UserControl c in this.panelVideo.Controls)
{
cnt++;
playlistName = playlistBase + cnt.ToString();
if (this.ScreenSettings.Shuffle)
filesShuffled = Shuffle(files);
else
filesShuffled = files;
VideoFrame vfr = (VideoFrame)c;
Microsoft.MediaPlayer.Interop.IWMPPlaylist pl;
pl = vfr.axWindowsMediaPlayer.mediaCollection.getByName(playlistName);
if (pl != null)
pl.clear();
else
pl = vfr.axWindowsMediaPlayer.playlistCollection.newPlaylist(
playlistName);
for(int i=0; i<=filesShuffled.Length-1; i++)
{
if (System.IO.File.Exists(filesShuffled[i]))
{
Microsoft.MediaPlayer.Interop.IWMPMedia m =
vfr.axWindowsMediaPlayer.newMedia(filesShuffled[i]);
pl.appendItem(m);
}
}
vfr.axWindowsMediaPlayer.currentPlaylist = pl;
}
foreach (UserControl c in this.panelVideo.Controls)
{
VideoFrame vfr = (VideoFrame)c;
vfr.axWindowsMediaPlayer.Ctlcontrols.play();
}
}
Requisite
Windows Media Player 9 or greater.
Updates / Fixes
- 21/10/2005: Changed form options language to English; fixed setup project that wasn't deploying a DLL.