在winform上实现视频播放常用的控件时media player,vs工具栏初始状态下没有,需要我们到com组件中添加。添加完成后,把media player控件拖拽到一个Form窗口中。
在此实现遍历某个文件夹下是否有mp4视频,如果有则播放视频。(可以不采用这种方式,直接播放某个地址的视频)
 DirectoryInfo dir = new DirectoryInfo(System.Windows.Forms.Application.StartupPath + "/Video");
             FileSystemInfo[] fileinfo = dir.GetFileSystemInfos();  //返回目录中所有文件和子目录
             foreach (FileSystemInfo i in fileinfo)
             {
                 //this.axWindowsMediaPlayer1.URL = "D/:路径/视频路径";//设置选中文件的路径为播放路径 
                 //this.axWindowsMediaPlayer1.URL = System.Windows.Forms.Application.StartupPath + "/Video/videotest.mp4";
this.MediaPlayerForm.URL = i.FullName;
                //视频处理
                 this.MediaPlayerForm.uiMode = "full";//"none"; // 隐藏MediaPlayer的用户界面 不能隐藏 调节声音大小
                 this.MediaPlayerForm.stretchToFit = true; // 将视频自动拉伸以适应窗体大小
                 this.MediaPlayerForm.settings.setMode("Loop", true);//循环播放
                 this.MediaPlayerForm.Dock = DockStyle.Fill;
                 this.MediaPlayerForm.Ctlcontrols.play();
             }