电脑播放器怎样关闭

发布时间: 2023-04-15 18:46 阅读: 文章来源:转载

1、取消播放器的自动播放功能

2、播放或者暂停按钮

3、下一曲、上一曲

4、多选删除

5、静音和放音

6、选择列表中的音乐文件,单击播放按钮直接播放

7、自动进行下一曲

15秒 44秒 当我和世界不一样

44.--47 那就让我不一样

lblInfomation.Text = musicPlayer.currentMedia.duration.ToString() + "\r\n" + musicPlayer.currentMedia.durationString + "\r\n" + musicPlayer.Ctlcontrols.currentPosition.ToString() + "\r\n" + musicPlayer.Ctlcontrols.currentPositionString;

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.IO;

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 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;

// musicPlayer.URL = @"C:\Users\SpringRain\Desktop\NewMusic\倔强.mp3";

label1.Image = Image.FromFile(@"C:\Users\SpringRain\Desktop\放音.jpg");

}

///

/// 播放或者暂停

///

///

///

///

bool b = true;

private void btnPlayorPause_Click(object sender, EventArgs e)

{

if (btnPlayorPause.Text == "播放")

{

if (b)

{

//获得选中的歌曲 让音乐从头播放

musicPlayer.URL = listPath[listBox1.SelectedIndex];

}

musicPlayer.Ctlcontrols.play();

btnPlayorPause.Text = "暂停";

}

else if (btnPlayorPause.Text == "暂停")

{

musicPlayer.Ctlcontrols.pause();

btnPlayorPause.Text = "播放";

b = false;

}

}

private void button3_Click_1(object sender, EventArgs e)

{

musicPlayer.Ctlcontrols.stop();

}

//存储音乐文件的全路径

List listPath = new List();

///

/// 打开对话框 选择音乐

///

///

///

private void button4_Click(object sender, EventArgs e)

{

OpenFileDialog ofd = new OpenFileDialog();

ofd.InitialDirectory = @"F:\老赵生活\music";

ofd.Filter = "音乐文件|*.wav|MP3文件|*.mp3|所有文件|*.*";

ofd.Title = "请选择音乐文件哟亲o(^▽^)o";

ofd.Multiselect = true;

ofd.ShowDialog();

//获得在文本框中选择文件的全路径

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("请首先选择音乐文件");

return;

}

try

{

musicPlayer.URL = listPath[listBox1.SelectedIndex];

musicPlayer.Ctlcontrols.play();

btnPlayorPause.Text = "暂停";

// lblInformation.Text = musicPlayer.currentMedia.duration.ToString();

IsExistLrc(listPath[listBox1.SelectedIndex]);

}

catch { }

}

///

/// 点击下一曲

///

///

///

private void button6_Click(object sender, EventArgs e)

{

//获得当前选中项的索引

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();

}

///

/// 点击上一曲

///

///

///

private void button5_Click(object sender, EventArgs e)

{

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();

}

///

/// 点击删除 选中项

///

///

///

private void 删除ToolStripMenuItem_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 label1_Click(object sender, EventArgs e)

{

if (label1.Tag.ToString() == "1")

{

//目的:让你静音

musicPlayer.settings.mute = true;

//显示静音的图片

label1.Image = Image.FromFile(@"C:\Users\SpringRain\Desktop\静音.jpg");

label1.Tag = "2";

}

else if (label1.Tag.ToString() == "2")

{

//放音

musicPlayer.settings.mute = false;

//显示放音的图片

label1.Image = Image.FromFile(@"C:\Users\SpringRain\Desktop\放音.jpg");

label1.Tag = "1";

}

}

///

/// 放大音量

///

///

///

private void button7_Click(object sender, EventArgs e)

{

musicPlayer.settings.volume += 5;

// MessageBox.Show(musicPlayer.settings.volume.ToString());

}

///

/// 减小声音

///

///

///

private void button8_Click(object sender, EventArgs e)

{

musicPlayer.settings.volume -= 5;

}

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;

}

#region 方法1

//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 = listTime[i] && musicPlayer.Ctlcontrols.currentPosition < listTime[i + 1])

{

label2.Text = listLrcText[i];

}

}

}

}

}

•••展开全文
相关文章