C# winform循環(huán)播放多個視頻
本文實例為大家分享了winform循環(huán)播放多個視頻的具體代碼,供大家參考,具體內(nèi)容如下
環(huán)境: vs2015 +winform
首先,vs自帶組件很方便,所以,用windowMediaplayer組件,如果做單曲循環(huán)播放的話,加個屬性:
axWindowsMediaPlayer1.settings.autoStart = true; //設(shè)置自動播放 axWindowsMediaPlayer1.settings.setMode("loop", true); //設(shè)置循環(huán)播放
言歸正傳:
一:拖入組件button ,windowMediaplayer,listbox,timer
二:
List<string> fileList = new List<string>(); private void button1_Click(object sender, EventArgs e) { fileList.Add(@"E:\\QLDownload\nba\\Action2.mp4"); fileList.Add(@"E:\\QLDownload\nba\\Action3.mp4"); fileList.Add(@"E:\\QLDownload\nba\\Action4.mp4"); fileList.Add(@"E:\\QLDownload\nba\\Action5.mp4"); for (int i = 0; i < fileList .Count ; i++) { listBox1.Items.Add(fileList [i]); } //默認選擇第一項 this.listBox1.SelectedIndex = 0; axWindowsMediaPlayer1 .URL = fileList [listBox1.SelectedIndex]; axWindowsMediaPlayer1 .Ctlcontrols.play(); } private void timer1_Tick(object sender, EventArgs e) { if (axWindowsMediaPlayer1 .playState == WMPLib.WMPPlayState.wmppsPlaying) { double d1 = Convert.ToDouble(axWindowsMediaPlayer1 .currentMedia.duration.ToString()); double d2 = Convert.ToDouble(axWindowsMediaPlayer1 .Ctlcontrols.currentPosition.ToString()) + 1; if (d1 <= d2) { nextMusic(listBox1.SelectedIndex); } } } private void Form1_Load(object sender, EventArgs e) { axWindowsMediaPlayer1 .settings.autoStart = false ; } void nextMusic(int index) { //listBox1.SelectedIndices.Clear(); index++; if (index == listBox1.Items.Count) { index = 0; } axWindowsMediaPlayer1 .URL = fileList [index]; listBox1.SelectedIndex = index; axWindowsMediaPlayer1 .Ctlcontrols.play(); }
提醒: 注意各個組件的自身屬性,運行不了,及時調(diào)屬性, .
由于需求原因,不讓選擇文件,所以在代碼里,默認添加的, 并把listbox隱藏了.
問題: 下面就要解決路徑問題了.如果打包,必須弄成項目路徑或者網(wǎng)絡(luò)路徑, 視頻文件并不支持內(nèi)置資源.
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
c#調(diào)用arcgis地圖rest服務(wù)示例詳解(arcgis地圖輸出)
ArcGIS REST API提供了簡單、開放的接口來訪問和使用ArcGIS Server發(fā)布的服務(wù)。使用ArcGIS REST API通過URL可以獲取和操作每一個服務(wù)中的所有資源和操作2013-12-12C#/VB.NET實現(xiàn)PPT或PPTX轉(zhuǎn)換為圖像功能
由于大多數(shù)便攜式設(shè)備支持瀏覽圖片而不支持瀏覽PowerPoint 文件,所以相比較而言,圖像對于用戶而言更加友好。本文將利用C#/VB.NET實現(xiàn)PPT或PPTX轉(zhuǎn)換為圖像功能,需要的可以參考一下2022-08-08C# DataTable.Select()根據(jù)條件篩選數(shù)據(jù)問題
這篇文章主要介紹了C# DataTable.Select()根據(jù)條件篩選數(shù)據(jù)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-01-01C#打包應(yīng)用程序,與.NETFramework介紹
C#打包應(yīng)用程序,與.NETFramework介紹,需要的朋友可以參考一下2013-05-05