winform下的简易播放器

时间:2023-11-17 10:42:08

winform下的简易播放器编写这个播放器,遇到很多问题,比如目前只实现了wav音频文件的播放,而对于这个图中中间所标注的按钮

不能实现让其暂停的功能,同时当点击的时候,让其文本变为"▷",对于这部分功能不知道选定该按钮时的属性是

如何,所以还需继续完善

播放器代码
 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Media;
using System.IO; namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ }
List<string> listSongs = new List<string>();//定义存储歌名的路径泛型变量
private void button5_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "请选择音频文件";
ofd.InitialDirectory =@"F:\wav_music";
ofd.Filter="音频文件|*.wav|所有文件|*.*";
ofd.Multiselect=true;//多选设置
ofd.ShowDialog();
string[] path = ofd.FileNames;//获取音频文件的全路径
for (int i = ; i < path.Length; i++)
{
listBox1.Items.Add(Path.GetFileName(path[i]));//将获取到的文件路径截取文件名并添加到listbox中
listSongs.Add(path[i]);//将路径添加到list集合当中 } }
/// <summary>
/// 双击播放音乐方法。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param> private void listBox1_DoubleClick(object sender, EventArgs e)
{
SoundPlayer sp = new SoundPlayer();//
sp.SoundLocation = listSongs[listBox1.SelectedIndex];
sp.Play();
}
/// <summary>
/// 播放下一首
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param> private void button4_Click(object sender, EventArgs e)
{
//获取当前所选定的音乐项
int index = listBox1.SelectedIndex;
index++;
SoundPlayer sp = new SoundPlayer();
if (index ==listSongs.Count)
{ index = ;
}
listBox1.SelectedIndex = index;//将索引重新赋值给listbox选定。
sp.SoundLocation = listSongs[index];
sp.Play(); }
/// <summary>
/// 播放上一首
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param> private void button2_Click(object sender, EventArgs e)
{
//获取当前所选定的音乐项
int index = listBox1.SelectedIndex;
index--;
SoundPlayer sp = new SoundPlayer();
if (index == )
{
index = listSongs.Count - ;
}
listBox1.SelectedIndex = index;
sp.SoundLocation = listSongs[index];
sp.Play(); }
}
}

相关文章