3个回答
展开全部
直接给你个代码吧!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);
}
}
}
}
详细情况 可以留言!
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);
}
}
}
}
详细情况 可以留言!
展开全部
实现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);
}
}
}
}
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);
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用windowmediaplayer控件
wmp控件是Active-X控件 默认在工具栏是不显示的
工具栏右键菜单 点击【选择列】 在弹出的选择窗口中点击【COM组件】 选择卡 里面你可以找到window media player控件的
wmp控件是Active-X控件 默认在工具栏是不显示的
工具栏右键菜单 点击【选择列】 在弹出的选择窗口中点击【COM组件】 选择卡 里面你可以找到window media player控件的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询