This article is mainly for you in detail the C # WinForm cycle to play a number of video related materials, with a certain reference value, interested in small partners can refer to
The example of this article for everyone to share the WinForm cycle to play a number of video specific code for your reference, the specific content as follows
Environment: vs2015 +winform
First of all, the VS comes with the component is very convenient, so, with the Windowmediaplayer component, if do single loop play, add a property:
AxWindowsMediaPlayer1.settings.autoStart = true; Set AutoPlay AxWindowsMediaPlayer1.settings.setMode ("loop", true); Set Loop playback
Anyway
One: Drag into the component button, Windowmediaplayer,listbox,timer
Two:
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]); }//By default Select the first item this.listBox1.SelectedIndex = 0; AxWindowsMediaPlayer1. URL = fileList [Listbox1.selectedindex]; AxWindowsMediaPlayer1. Ctlcontrols.play (); private void Timer1_Tick (object sender, EventArgs e) {if (axWindowsMediaPlayer1. playstate = = Wmplib.wmpplaysta te.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 = f Alse; }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 (); }
Reminder: Note the individual components of their own properties, can not run, timely adjustment of properties,.
Because of the demand reasons, do not let the selection of files, so in the code, added by default, and the ListBox is hidden.
problem: The path problem is solved below. If you package, you must make a project path or network path, the video file does not support built-in resources.