zoukankan      html  css  js  c++  java
  • c#音乐播放器


    using
    System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Media; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace 音乐播放器 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } List<string> Music = new List<string>(); private void button1_Click(object sender, EventArgs e) { //打开一个对话框,提示用户选择文件 OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = ("请选择音乐文件"); //文本框标题 ofd.InitialDirectory = @"D:FFOutput"; //默认打开的文件夹 ofd.Multiselect = true; //允许对话框选择多个文件 ofd.Filter = "音乐文件|*.wav|所有文件|*.*"; //可选的文件类型 ofd.ShowDialog(); //显示对话框 //将所有选中的文件添加到listbox中 string[] path = ofd.FileNames; //获取被选择文件的全路径 for (int i = 0; i < path.Length; i++) { listBox1.Items.Add(Path.GetFileName(path[i])); //将音乐文件添加到ListBox中 Music.Add(path[i]); //将音乐文件的全路径添加到List集合中 } } SoundPlayer sp = new SoundPlayer(); //播放对象 //双击歌曲播放 private void listBox1_DoubleClick(object sender, EventArgs e) { sp.SoundLocation = Music[listBox1.SelectedIndex]; //ListBox1中选中的文件的索引 sp.Play(); } //下一曲 private void button3_Click(object sender, EventArgs e) { int index = listBox1.SelectedIndex; //获取当前选中歌曲的索引 //if(index != listBox1.Items.Count-1) //{ // index++; //下一曲时索引自增 //} //else if(index==listBox1.Items.Count-1) //当前选中歌曲索引为最后一首歌时,重新回到第一曲 //{ // index = 0; //} index++; if(index == listBox1.Items.Count) { index = 0; } sp.SoundLocation = Music[index]; listBox1.SelectedIndex = index; sp.Play(); } //上一曲 private void button2_Click(object sender, EventArgs e) { int index = listBox1.SelectedIndex; //获取当前选中歌曲的索引 //if(index != 0) //{ // index--; //上一曲时索引自增 //} //else if (index == 0) //当前选中歌曲索引为最后一首歌时,重新回到第一曲 //{ // index = listBox1.Items.Count-1; //} if (index == 0) { index = listBox1.Items.Count-1; } else { index--; } sp.SoundLocation = Music[index]; listBox1.SelectedIndex = index; sp.Play(); } private void button4_Click(object sender, EventArgs e) { //Thread.Sleep(); } } }
  • 相关阅读:
    设计模式网页资料
    委托的begininvoke
    C# 给某个方法设定执行超时时间
    C#中的Invoke----control上的以及delegate的是不一样的
    如何在windows中部署Gitblit
    sqlserver数据库出错的解决方法
    追索权 Eclipse + NDK error: stray &#39;24&#39; in program
    Linux课程_系统配置和日常维护
    1007: 童年二三事
    开源:矿Android新闻client,快、小、支持离线阅读、操作简单、内容丰富,形式多样展示、的信息量、全功能 等待(离开码邮箱)
  • 原文地址:https://www.cnblogs.com/decoct-tea/p/12369885.html
Copyright © 2011-2022 走看看