Detailed code example for C#winform loop to play multiple videos

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.