• 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(); } } }
  • 相关阅读:
    js点击按钮为元素随机字体颜色和背景色
    js随即数字random实现div点击更换背景色
    while循环计算1-100和,1-100内偶数/奇数/被整除的数的和
    慕课手机展示页案例
    第3题:求子数组的最大和
    第4题:在二叉树中找出和为某一值的所有路径
    第5题:查找最小的K个元素
    Linux系统开启IPv6任播(anycast)地址
    第7题:判断两个链表是否相交
    第8题上:思维题
  • 原文地址:https://www.cnblogs.com/decoct-tea/p/12369885.html
Copyright © 2020-2023  润新知