在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();
? ? ? ? ? ? }