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(); } } }
  • 相关阅读:
    2013,爱上暗色调
    [转]Sublime Text 使用介绍、全套快捷键及插件推荐
    委托、事件
    ASP.NET中常用的三十三种代码 .NET技术 / ASP.NET
    台湾综艺节目
    C# 中的委托和事件
    ASP.net 静态化页面之的URL重写
    源码
    毕业5年决定你的一生
    常见错误 不能打开注册表关键字
  • 原文地址:https://www.cnblogs.com/decoct-tea/p/12369885.html
Copyright © 2011-2022 走看看