C# winform循环播放多个视频

作者:鬼谷神奇 时间:2021-06-30 06:39:21 

本文实例为大家分享了winform循环播放多个视频的具体代码,供大家参考,具体内容如下

环境: vs2015 +winform

首先,vs自带组件很方便,所以,用windowMediaplayer组件,如果做单曲循环播放的话,加个属性:


axWindowsMediaPlayer1.settings.autoStart = true;      //设置自动播放
axWindowsMediaPlayer1.settings.setMode("loop", true);   //设置循环播放

言归正传:

一:拖入组件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();
   }

提醒: 注意各个组件的自身属性,运行不了,及时调属性, .

由于需求原因,不让选择文件,所以在代码里,默认添加的, 并把listbox隐藏了.

问题: 下面就要解决路径问题了.如果打包,必须弄成项目路径或者网络路径, 视频文件并不支持内置资源.

标签:C#,winform,视频
0
投稿

猜你喜欢

  • Java Lambda表达式超详细介绍

    2021-09-25 03:16:43
  • Java设计模式之观察者模式_动力节点Java学院整理

    2022-01-14 12:27:47
  • Java MapStruct解了对象映射的毒

    2022-08-20 11:37:12
  • C#截图程序类似腾讯QQ截图实现代码

    2023-05-07 04:01:01
  • java实现电话本管理系统

    2023-10-11 14:51:19
  • java生成饼图svg及JFreeChart生成svg图表

    2023-10-25 19:27:00
  • 基于C#的图表控件库 ScottPlot编译visual studio 2022

    2022-05-02 10:24:13
  • java统计字符串中指定元素出现次数方法

    2022-11-02 16:05:40
  • Spring Boot 启动加载数据 CommandLineRunner的使用

    2021-06-17 12:52:21
  • Android实现截屏方式整理(总结)

    2023-12-07 05:10:18
  • Android Studio 报错failed to create jvm error code -4的解决方法

    2023-01-22 03:13:49
  • Java中判断对象是否为空的方法的详解

    2022-01-09 07:41:14
  • C#提取网页中超链接link和text部分的方法

    2023-02-24 02:04:14
  • java读取xml配置参数代码实例

    2023-11-25 03:03:17
  • Java编程调用微信接口实现图文信息推送功能

    2023-11-25 07:20:47
  • 使用eclipse创建java项目的方法

    2022-10-15 04:41:00
  • Android自定义View圆形图片控件代码详解

    2022-05-15 12:00:53
  • Java Maven高级之插件开发详解

    2023-05-11 19:10:02
  • Java常用集合与原理解析

    2023-04-01 14:26:42
  • C#多线程基础知识汇总

    2023-03-06 08:35:47
  • asp之家 软件编程 m.aspxhome.com