openFileDialog1.Filter = "mp3文件(*.mp3;)|*.mp3|所有文件(*.*)|*.*";
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
textBox5.Text = System.IO.Path.GetFileName(this.openFileDialog1.FileName);
//*********************************************
//播放发音
string name = this.openFileDialog1.FileName;
///产生短路径名
StringBuilder shortpath = new StringBuilder(80);
int result = GetShortPathName(name, shortpath, shortpath.Capacity);
name = shortpath.ToString();
mciSendString(@"close all", null, 0, 0);
mciSendString(@"open " + name + " alias song", null, 0, 0); //打开
mciSendString("play song", null, 0, 0); //播放
//**********************************************
}
catch (Exception) { }
}///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// 使用API
/// </summary>
public static uint SND_ASYNC = 0x0001; // play asynchronously
public static uint SND_FILENAME = 0x00020000; // 按文件名播放
[DllImport("winmm.dll")]
public static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2); [DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path, StringBuilder shortPath, Int32 shortPathLength);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
自己改改吧
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
textBox5.Text = System.IO.Path.GetFileName(this.openFileDialog1.FileName);
//*********************************************
//播放发音
string name = this.openFileDialog1.FileName;
///产生短路径名
StringBuilder shortpath = new StringBuilder(80);
int result = GetShortPathName(name, shortpath, shortpath.Capacity);
name = shortpath.ToString();
mciSendString(@"close all", null, 0, 0);
mciSendString(@"open " + name + " alias song", null, 0, 0); //打开
mciSendString("play song", null, 0, 0); //播放
//**********************************************
}
catch (Exception) { }
}///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// 使用API
/// </summary>
public static uint SND_ASYNC = 0x0001; // play asynchronously
public static uint SND_FILENAME = 0x00020000; // 按文件名播放
[DllImport("winmm.dll")]
public static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2); [DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path, StringBuilder shortPath, Int32 shortPathLength);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
自己改改吧
解决方案 »
- .NET程序有没有法子不要求客户装FRAMEWORK?
- FastCopy如何使用命令行 在拷贝结束好执行第三方程序!
- 哈希表
- c# 上传图片展现问题
- 提问:高级程序员与初级程序员的区别是什么?
- 如何用变量定义DataRow的名称?
- C#里可有C++里的union数据类型?
- 打开文件后,conn链接打开出现问题,提示路径出问题。请问高手怎么解决?
- 水晶报表导出word的页面设置,高手请进
- 多窗口操作呀,我该怎么办,我想哭了呀
- 在读取Excel文件时,遇到粗体字就读不出来了,有什么办法么?
- 为什么我写的邮件发送程序中只能发送英文字符串,而发送的汉字用邮箱接收显示的是乱码,我是把字符串转换成UTF8
public static uint SND_ASYNC = 0x0001; // play asynchronously
public static uint SND_FILENAME = 0x00020000; // name is file name
[DllImport("winmm.dll")]
public static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2); [DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path,StringBuilder shortPath, Int32 shortPathLength); 这些代码放在最前面,表示引入两个winmm库
然后再窗体启动的load事件中添加如下代码即可:
string name = @"E:\Music\故乡的原风景.mp3";
System.Text.StringBuilder shortpath = new System.Text.StringBuilder(80);
int result = GetShortPathName(name, shortpath, shortpath.Capacity);
name = shortpath.ToString();
mciSendString(@"close all", null, 0, 0);
mciSendString(@"open " + name + " alias song", null, 0, 0); //打开
mciSendString("play song", null, 0, 0); //播放
string MyFileName="C:\\音乐名.mp3";
QuartzTypeLib.FilgraphManager grahManager=new QuartzTypeLib.FilgraphManager();
QuartzTypeLib.IMediaControl control=(QuartzTypeLib.IMediaControl)grahManager;
control.RenderFile(MyFileName);
control.Run();在项目->添加引用->浏览->[windows目录]->system32->quartz.dll
呵呵,这是系统自带的,我最近刚好要写个多媒体播放器,用到它。其实所有的应用程序都是用的windows函数。只不过有些常用的vc#将它封装拉。
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// private delegate void player();
private void plaermusic()
{
string MyFileName = "E:\\音乐\\其他\\forever-friends.mp3";
QuartzTypeLib.FilgraphManager grahManager = new QuartzTypeLib.FilgraphManager();
QuartzTypeLib.IMediaControl control = (QuartzTypeLib.IMediaControl)grahManager;
control.RenderFile(MyFileName);
control.Run(); } private void Form1_Load(object sender, EventArgs e)
{
new System.Threading.Thread(new System.Threading.ThreadStart(plaermusic)).Start();
}
}
}
QuartzTypeLib这个的引用在哪里可以找到啊?