基本信息
源码名称:基于C#编写的音乐播放器(入门级)
源码大小:58.50M
文件格式:.7z
开发语言:C#
更新时间:2018-11-19
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 3 元×
微信扫码支付:3 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
具备播放器的普通功能 笑脸哭脸放/静音切换
【调试步骤】
Open 找到 音乐文件 打开后,选中 左侧栏的音乐 点击 Play 就可以播放了
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Media;
namespace Music_Player
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MusicPlayer.Ctlcontrols.play();
}
private void button2_Click(object sender, EventArgs e)
{
MusicPlayer.Ctlcontrols.pause();
}
private void button3_Click(object sender, EventArgs e)
{
MusicPlayer.Ctlcontrols.stop();
}
private void Form1_Load(object sender, EventArgs e)
{
MusicPlayer.settings.autoStart = false;
label1.Image = Image.FromFile(@"Label\Play.png");
}
/// <summary>
/// Play/Pause
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
bool b = true;
private void button4_Click(object sender, EventArgs e)
{
if (btnPlayorPause.Text == "Play")
{ //获得选中的歌曲
if (b)
{ //让音乐从头播放
MusicPlayer.URL = listPath[listBox1.SelectedIndex];
}
MusicPlayer.Ctlcontrols.play();
btnPlayorPause.Text = "Pause";
}
else if (btnPlayorPause.Text == "Pause")
{
MusicPlayer.Ctlcontrols.pause();
btnPlayorPause.Text = "Play";
b = false;
}
}
private void button5_Click(object sender, EventArgs e)
{
MusicPlayer.Ctlcontrols.stop();
}
//Save full path of Music File
List<string> listPath = new List<string>();
/// <summary>
/// Open select Music
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click_1(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = @"Musics";
ofd.Filter = "所有文件|*.*|音乐文件|*.wav|MP3文件|*,mp3";
ofd.Title = "Please select music File";
ofd.Multiselect = true;
ofd.ShowDialog();
//Get path of file
string[] path = ofd.FileNames;
for (int i = 0; i < path.Length; i )
{//将音乐文件的全路径存储到泛型集合中
listPath.Add(path[i]);
//将音乐文件的文件名存储到ListBox中
listBox1.Items.Add(Path.GetFileName(path[i]));
}
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
if (listBox1.Items.Count == 0)
{
MessageBox.Show("Firstly,Please select music File ");
return;
}
try
{
MusicPlayer.URL = listPath[listBox1.SelectedIndex];
MusicPlayer.Ctlcontrols.play();
btnPlayorPause.Text = "Pause";
//lblInformation.Text = MusicPlayer.currentMedia.duration.ToString();
}
catch { }
}
//Down
private void button2_Click_1(object sender, EventArgs e)
{
try
{
int index = listBox1.SelectedIndex;
//清空所有选中项的索引
listBox1.SelectedIndices.Clear();
index ;
if (index == listBox1.Items.Count)
{
index = 0;
}
//将改变后的索引重新赋值给当前选中项的索引
listBox1.SelectedIndex = index;
MusicPlayer.URL = listPath[index];
MusicPlayer.Ctlcontrols.play();
}
catch { }
}
/// <summary>
/// UP
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click_1(object sender, EventArgs e)
{
try
{
int index = listBox1.SelectedIndex;
//清空所有选中项的索引
listBox1.SelectedIndices.Clear();
index--;
if (index < 0)
{
index = listBox1.Items.Count - 1;
}
//将改变后的索引重新赋值给当前选中项的索引
listBox1.SelectedIndex = index;
MusicPlayer.URL = listPath[index];
MusicPlayer.Ctlcontrols.play();
}
catch
{ }
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
}
private void contextMenuStrip2_Opening(object sender, CancelEventArgs e)
{
}
/// <summary>
/// Play/Mute
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void label1_Click(object sender, EventArgs e)
{
if (label1.Tag.ToString() == "1")
{
//Mute
MusicPlayer.settings.mute = true;
label1.Image = Image.FromFile(@"Label\Mute.png");
label1.Tag = "2";
}
else if (label1.Tag.ToString() == "2")
{
MusicPlayer.settings.mute = false;
label1.Image = Image.FromFile(@"Label\Play.png");
label1.Tag = "1";
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (MusicPlayer.playState == WMPLib.WMPPlayState.wmppsPlaying)
{
lblInformation.Text = MusicPlayer.currentMedia.duration.ToString() "\r\n" MusicPlayer.currentMedia.durationString "\r\n" MusicPlayer.Ctlcontrols.currentPosition.ToString() "\r\n" MusicPlayer.Ctlcontrols.currentPositionString;
double d1 = double.Parse(MusicPlayer.currentMedia.duration.ToString());
double d2 = double.Parse(MusicPlayer.Ctlcontrols.currentPosition.ToString()) 1;
if (d1 <= d2)
{
try
{
int index = listBox1.SelectedIndex;
//清空所有选中项的索引
listBox1.SelectedIndices.Clear();
index ;
if (index == listBox1.Items.Count)
{
index = 0;
}
//将改变后的索引重新赋值给当前选中项的索引
listBox1.SelectedIndex = index;
MusicPlayer.URL = listPath[index];
MusicPlayer.Ctlcontrols.play();
}
catch { }
}
}
}
/// <summary>
/// 放大声音
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button4_Click_1(object sender, EventArgs e)
{
MusicPlayer.settings.volume = 5;
}
/// <summary>
/// 减小音量
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button6_Click(object sender, EventArgs e)
{
MusicPlayer.settings.volume -= 5;
}
private void contextMenuStrip3_Opening(object sender, CancelEventArgs e)
{
}
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
//先删列表还是先删集合?
//首先获得要删除的歌曲的数量
int count = listBox1.SelectedItems.Count;
for (int i = 0; i < count; i )
{
//先删集合
listPath.RemoveAt(listBox1.SelectedIndex);
}
//再删列表
listBox1.Items.RemoveAt(listBox1.SelectedIndex);
}
private void button8_Click(object sender, EventArgs e)
{
SoundPlayer sp = new SoundPlayer();
sp.PlayLooping();
}
private void button8_Click_1(object sender, EventArgs e)
{
}
}
}