AxMediaPlayer控件使用方法(非AxWindowsMediaPlayer控件)
一:c#中播放MP3文件
首先,我们要生成MediaPlayer.dll 和 AxMediaPlayer.dll控件:
方法如下:命令为:aximp c:\winnt\system32\msdxm.ocx 而通常 msdxm.ocx中的ActiveX控件都未注册! 则先运行regsvr32 msdxm.ocx手动注册便生成需要的动态连接库文件。
其次:填写程序如下:
private void button1_Click(object sender, System.EventArgs e)
{//浏览MP3文件
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
this.listView1.Items.Clear();
string []FileNames=this.openFileDialog1.FileNames;
foreach(string FileName in FileNames)
{
//取得文件大小
FileInfo MyFileInfo=new FileInfo(FileName);
float MyFileSize=(float)MyFileInfo.Length/(1024*1024);
this.axMediaPlayer1.FileName=FileName;
//取得作者信息
string MyAuthor=this.axMediaPlayer1.GetMediaInfoString(MediaPlayer.MPMediaInfoType.mpClipAuthor);
//取得不含路径的文件名
string MyShortFileName=FileName.Substring(FileName.LastIndexOf("\\")+1);
MyShortFileName=MyShortFileName.Substring(0,MyShortFileName.Length-4);
//填充歌曲列表
string[] SubItem={MyShortFileName,MyAuthor,MyFileSize.ToString().Substring(0,4)+"M",FileName};
ListViewItem Item=new ListViewItem(SubItem);
this.listView1.Items.Add(Item);
this.listView1.Items[0].Selected=true;
}
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余4页未读,立即下载