AviScreensaver: 一个允许您播放收藏媒体文件的 C# 屏幕保护程序





0/5 (0投票)
该屏幕保护程序可以同时播放 1 到 16 个视频(或媒体文件)。
引言
一个屏幕保护程序包含一个窗体,可以加载 1 到 16 个 Windows MediaPlayer
控件。每个 MediaPlayer
控件加载用户选择的媒体文件,将它们存储在随机播放列表中,然后播放所有媒体文件。它可以播放 Windows Media Player 支持的所有格式(视频文件、图像文件、音乐)。
private void ScreenSaverForm_Load(object sender, System.EventArgs e)
{
Cursor.Hide();
TopMost = true;
// uso playlist perchè in futuro potrò selezionare più files
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;
}
// aggiungo i files della cartella
if (folderFiles!=null)
folderFiles.CopyTo(files, startIndex);
// randomizzo
string[] filesShuffled;
// nota bene:
// anche se posso gestire più riquadri video
// in questo momento ne uso sempre e SOLO 1
// perchè media player si arrabbia con più video in simultanea
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;
}
// lancio i play tutti insieme
foreach (UserControl c in this.panelVideo.Controls)
{
VideoFrame vfr = (VideoFrame)c;
vfr.axWindowsMediaPlayer.Ctlcontrols.play();
}
}
必备条件
Windows Media Player 9 或更高版本。
更新 / 修复
- 2005年10月21日:将窗体选项语言更改为英语;修复了未部署 DLL 的安装项目。