- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace wanwanjingting
- {
- public partial class Form1 : Form
- {
- private String [] filenames=new string[100];
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- timer1.Start(); //设置定时器
- timer1.Interval = 1000;
- timer1.Tick += new EventHandler(timer1_Tick);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- OpenFileDialog fdlg = new OpenFileDialog(); //创建一个文件对话框
- fdlg.InitialDirectory = "d://"; //初始化目录
- fdlg.Multiselect = true; //可以复选
- if (fdlg.ShowDialog() == DialogResult.OK)
- {
- filenames=fdlg.FileNames; //往播放列表中添加选中的文件
- foreach (String a in filenames)
- {
- listBox1.Items.Add(a);
- }
- axWindowsMediaPlayer1.URL = filenames[listBox1.SelectedIndex+1];
- }
- }
- private void listBox1_SelectedIndexChanged(object sender, EventArgs e) //当选择改变时播放这一首
- {
- if (listBox1.SelectedItem!=null)
- axWindowsMediaPlayer1.URL = filenames[listBox1.SelectedIndex];
- }
- private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
- {
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (axWindowsMediaPlayer1.playState == (WMPLib.WMPPlayState)1) //循环播放
- {
- if (listBox1.SelectedIndex ==listBox1.Items.Count-1) //如果当前播放是最后一首就从第一首开始播放
- {
- listBox1.SelectedIndex = 0;
- }
- else //如果当前播放不是最后一首就播放下一首
- {
- listBox1.SelectedIndex++;
- axWindowsMediaPlayer1.URL = filenames[listBox1.SelectedIndex + 1];
- }
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- listBox1.Items.Remove(listBox1.SelectedItem);
- }
- }
- }
自己做的一个千千静听
最新推荐文章于 2022-03-15 10:45:52 发布