基本信息
源码名称:简单的音乐播放器(支持wav文件播放)
源码大小:0.06M
文件格式:.zip
开发语言:C#
更新时间:2019-03-07
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
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();
}
List<string> listsongs = new List<string>();
SoundPlayer sp = new SoundPlayer();
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog of = new OpenFileDialog();
of.Title = "请选择要添加的音乐文件";
of.Filter= @"音乐文件|*.mp3||*.wav|所有文件|*.*";
if (of.ShowDialog() == DialogResult.OK)
{
string[] pa_th = of.FileNames;
for (int i = 0; i < pa_th.Length; i )
{
listBox1.Items.Add(Path.GetFileName(pa_th[i]));
listsongs.Add(pa_th[i]);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
int Index = listBox1.SelectedIndex;
Index ;
if (Index == listBox1.Items.Count)
{
Index = 0;
}
listBox1.SelectedIndex = Index;
sp.SoundLocation = listsongs[Index];
sp.Play();
}
private void button2_Click(object sender, EventArgs e)
{
int Index = listBox1.SelectedIndex;
Index--;
if (Index < 0)
{
Index = listBox1.Items.Count - 1;
}
listBox1.SelectedIndex = Index;
sp.SoundLocation = listsongs[Index];
sp.Play();
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
SoundPlayer sp1 = new SoundPlayer();
sp1.SoundLocation = listsongs[listBox1.SelectedIndex];
sp1.Play();
}
}
}