C#常⽤控件项⽬(⾳乐播放器)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;
namespace ⾳乐播放器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//添加⾳乐⽂件
private void btn_add_Click(object sender, EventArgs e)
{
谁的心谁独自流浪 //实例化⼀个⽂件对话框
OpenFileDialog fd = new OpenFileDialog();
//设置对话框属性:标题
小背篓铃声 fd.Title = "选择⾳乐⽂件";
//设置⽂件扩展名筛选
fd.Filter = "(⾳乐⽂件).mp3.mp4.wav|*.mp3;*.mp4;*.wav;";
//设置多选
fd.Multiselect = true;
//显⽰对话框
av女星 DialogResult dr = fd.ShowDialog();
if (dr == DialogResult.OK) //点击的是确定按钮
{
//获取所有选择的⾳乐⽂件名--数组
string[] fns = fd.FileNames;
//把选择的⾳乐⽂件名添加到列表框ListBox
foreach (string fn in fns)
{
this.listBox1.Items.Add(fn);
}
}
}
private void btn_bf_Click(object sender, EventArgs e)
郑嘉颖与周丽淇{
if (this.listBox1.SelectedIndex == -1)
{ //如果没有选中歌曲,默认选择第⼀⾸
chocolate ice this.listBox1.SelectedIndex = 0;
}
//播放⾳乐 = 获取列表框的当前选中项
this.wmp_mm.URL = this.listBox1.SelectedItem.ToString();
//启动定时器
this.timer1.Start();
}
//时时刻刻检测播放器是否播放完毕
int s = 0;
private void timer1_Tick(object sender, EventArgs e)
{
//设置进度条的进度
if (s <= this.progressBar1.Maximum) //不能超过进度条的上限
{
this.progressBar1.Value = s++;
}
//如果播放器的播放状态为停⽌状态 Ctrl+J
if (this.wmp_mm.playState == WMPLib.WMPPlayState.wmppsStopped) {
//设置列表框选中下⼀个
int xb = this.listBox1.SelectedIndex;
xb++;
if (xb == this.listBox1.Items.Count)
{ //如果到了最后⼀⾸,回到第⼀⾸
xb = 0;
}
this.listBox1.SelectedIndex = xb;
//设置播放器URL
this.wmp_mm.URL = this.listBox1.SelectedItem.ToString();
}
}
}
}
/
/因为⼯具箱没有⾳乐播放⼯具我们要导⼊windows⾃带的播放器
添加播放器控件说明:
终极一班3的歌曲第⼀步:添加选项卡-为选项卡命名
第⼆步:在这个选项卡⾥⾯右键->选择项
第三步:到COM组件->Windows Media Player
//窗体UI设计
发布评论