C# 音乐播放器怎么弄

请说的详细些那个控件怎么添加?... 请说的详细些
那个控件怎么添加?
展开
 我来答
qiliping666
推荐于2017-11-23 · TA获得超过925个赞
知道小有建树答主
回答量:369
采纳率:33%
帮助的人:65万
展开全部
直接给你个代码吧!using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace MP3File
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}

/// <summary>
/// 浏览MP3文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Open_Click(object sender, EventArgs e)
{
if (this.oFDlog_Info.ShowDialog() == DialogResult.OK)
{
this.lV_Info.Items.Clear();
string[] FileNames = this.oFDlog_Info.FileNames;
foreach (string FileName in FileNames)
{
//取得文件大小
FileInfo FileInfo = new FileInfo(FileName);
float FileSize = (float)FileInfo.Length / (1024 * 1024);
this.axMP_Info.FileName = FileName;
//取得作者信息
string Author = this.axMP_Info.GetMediaInfoString(MediaPlayer.MPMediaInfoType.mpClipAuthor);
//取得不含路径的文件名
string ShortFileName = FileName.Substring(FileName.LastIndexOf("\\") + 1);
ShortFileName = ShortFileName.Substring(0, ShortFileName.Length - 4);
//填充歌曲列表
string[] SubItem ={ ShortFileName, Author, FileSize.ToString().Substring(0, 4) + "M", FileName };
ListViewItem Item = new ListViewItem(SubItem);
this.lV_Info.Items.Add(Item);
this.lV_Info.Items[0].Selected = true;
}
}
}

/// <summary>
/// 播放MP3文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Play_Click(object sender, EventArgs e)
{
if (this.lV_Info.Items.Count > 0)
{
if (this.lV_Info.SelectedItems.Count > 0)
{
int iPos = this.lV_Info.SelectedItems[0].Index;
string FileName = this.lV_Info.Items[iPos].SubItems[3].Text.ToString();
this.axMP_Info.FileName = FileName;
this.axMP_Info.Play();
}
}
else
{
MessageBox.Show("请选择歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

/// <summary>
/// 暂停播放
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Pase_Click(object sender, EventArgs e)
{
if (this.axMP_Info.FileName.Length > 0)
this.axMP_Info.Pause();
else
{
MessageBox.Show("请选择歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

/// <summary>
/// 上一首歌曲
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Pre_Click(object sender, EventArgs e)
{
if (this.lV_Info.Items.Count > 0)
{
if (this.lV_Info.SelectedItems.Count > 0)
{
int iPos = this.lV_Info.SelectedItems[0].Index;
if (iPos > 0)
{
this.lV_Info.Items[iPos - 1].Selected = true;
string FileName = this.lV_Info.Items[iPos - 1].SubItems[3].Text.ToString();
this.axMP_Info.FileName = FileName;
this.axMP_Info.Play();
}
else
{
MessageBox.Show("已经是第一首歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
else
{
MessageBox.Show("请选择歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

/// <summary>
/// 下一首歌曲
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Next_Click(object sender, EventArgs e)
{
if (this.lV_Info.Items.Count > 0)
{
if (this.lV_Info.SelectedItems.Count > 0)
{
int iPos = this.lV_Info.SelectedItems[0].Index;
if (iPos < this.lV_Info.Items.Count - 1)
{
this.lV_Info.Items[iPos + 1].Selected = true;
string FileName = this.lV_Info.Items[iPos + 1].SubItems[3].Text.ToString();
this.axMP_Info.FileName = FileName;
this.axMP_Info.Play();
}
else
{
MessageBox.Show("已经是最后一首歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
else
{
MessageBox.Show("请选择歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

/// <summary>
/// 停止播放
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Stop_Click(object sender, EventArgs e)
{
if (this.axMP_Info.FileName.Length > 0)
this.axMP_Info.Stop();
else
{
MessageBox.Show("请选择歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}

详细情况 可以留言!
一骑当后
推荐于2016-09-21 · 知道合伙人数码行家
一骑当后
知道合伙人数码行家
采纳数:40298 获赞数:306436
网络、设备维护、电路、弱电检测。

向TA提问 私信TA
展开全部
实现C#音乐播放器代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace MP3File
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}

/// <summary>
/// 浏览MP3文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Open_Click(object sender, EventArgs e)
{
if (this.oFDlog_Info.ShowDialog() == DialogResult.OK)
{
this.lV_Info.Items.Clear();
string[] FileNames = this.oFDlog_Info.FileNames;
foreach (string FileName in FileNames)
{
//取得文件大小
FileInfo FileInfo = new FileInfo(FileName);
float FileSize = (float)FileInfo.Length / (1024 * 1024);
this.axMP_Info.FileName = FileName;
//取得作者信息
string Author = this.axMP_Info.GetMediaInfoString(MediaPlayer.MPMediaInfoType.mpClipAuthor);
//取得不含路径的文件名
string ShortFileName = FileName.Substring(FileName.LastIndexOf("\\") + 1);
ShortFileName = ShortFileName.Substring(0, ShortFileName.Length - 4);
//填充歌曲列表
string[] SubItem ={ ShortFileName, Author, FileSize.ToString().Substring(0, 4) + "M", FileName };
ListViewItem Item = new ListViewItem(SubItem);
this.lV_Info.Items.Add(Item);
this.lV_Info.Items[0].Selected = true;
}
}
}

/// <summary>
/// 播放MP3文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Play_Click(object sender, EventArgs e)
{
if (this.lV_Info.Items.Count > 0)
{
if (this.lV_Info.SelectedItems.Count > 0)
{
int iPos = this.lV_Info.SelectedItems[0].Index;
string FileName = this.lV_Info.Items[iPos].SubItems[3].Text.ToString();
this.axMP_Info.FileName = FileName;
this.axMP_Info.Play();
}
}
else
{
MessageBox.Show("请选择歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

/// <summary>
/// 暂停播放
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Pase_Click(object sender, EventArgs e)
{
if (this.axMP_Info.FileName.Length > 0)
this.axMP_Info.Pause();
else
{
MessageBox.Show("请选择歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

/// <summary>
/// 上一首歌曲
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Pre_Click(object sender, EventArgs e)
{
if (this.lV_Info.Items.Count > 0)
{
if (this.lV_Info.SelectedItems.Count > 0)
{
int iPos = this.lV_Info.SelectedItems[0].Index;
if (iPos > 0)
{
this.lV_Info.Items[iPos - 1].Selected = true;
string FileName = this.lV_Info.Items[iPos - 1].SubItems[3].Text.ToString();
this.axMP_Info.FileName = FileName;
this.axMP_Info.Play();
}
else
{
MessageBox.Show("已经是第一首歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
else
{
MessageBox.Show("请选择歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

/// <summary>
/// 下一首歌曲
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Next_Click(object sender, EventArgs e)
{
if (this.lV_Info.Items.Count > 0)
{
if (this.lV_Info.SelectedItems.Count > 0)
{
int iPos = this.lV_Info.SelectedItems[0].Index;
if (iPos < this.lV_Info.Items.Count - 1)
{
this.lV_Info.Items[iPos + 1].Selected = true;
string FileName = this.lV_Info.Items[iPos + 1].SubItems[3].Text.ToString();
this.axMP_Info.FileName = FileName;
this.axMP_Info.Play();
}
else
{
MessageBox.Show("已经是最后一首歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
else
{
MessageBox.Show("请选择歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

/// <summary>
/// 停止播放
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Stop_Click(object sender, EventArgs e)
{
if (this.axMP_Info.FileName.Length > 0)
this.axMP_Info.Stop();
else
{
MessageBox.Show("请选择歌曲!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
古月下234
2012-08-20
知道答主
回答量:52
采纳率:0%
帮助的人:8.1万
展开全部
用windowmediaplayer控件

wmp控件是Active-X控件 默认在工具栏是不显示的
工具栏右键菜单 点击【选择列】 在弹出的选择窗口中点击【COM组件】 选择卡 里面你可以找到window media player控件的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式