Windows Media Player axwindowsmediaplayer控件的使用

fashionbrot 2011-12-11 09:57:05
axwindowsmediaplayer C# 窗体中axwindowsmediaplayer这个空间怎么使用?axwindowsmediaplayer.什么是播放,.什么是停止呢?请前辈赐教:
...全文
83 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fashionbrot 2011-12-12
  • 打赏
  • 举报
回复
你这this.axMediaPlayer1.Play(); this.axMediaPlayer1.Pause(); 都.不出来啊
csdn_aspnet 2011-12-11
  • 打赏
  • 举报
回复
一: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;
}

}
}

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


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

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

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

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

}

二:C#中播放AVI短片并使背景透明

我发现他所用的MediaPlayer控件是可以播放许多的媒体文件.但是并不能满足我所需要的情况。我的情况是用C#播放一小段AVI文件,并且背景要透明,而不是黑色,或其他颜色,我找了半天也不能找到什么方法可以使MediaPlayer播放的文件为透明的状态,十分郁闷!

但是随后我发现其他用VB的程序中可以实现这个功能,让我十分的高兴,于是我又打开了VB的代码进行了详细的查看,发现在VB中有一个控件为Animation可以播放AVI文件,而且其有一个属性选项是使背景透明。正好能够满足我的需要.可是这也是一个OCX的控件,于是,我先把该控件找到,位置是:C:\WINDOWS\SYSTEM32\COMCT32.ocx,然后我运行regsvr32进行手动注册,注册完毕以后我就在环境中进行引用,如下图:

(但是,后来本人发现原来这个根本不用regsvr32注册,因为.NET早已经注册了,郁闷中~~~~~~~~~~~~~~)

然后把控件拖入到窗体中,布好了局,将其属性AutoPlay设置为true,然后在代码中写入下边一句话即可:

private void Form1_Load(object sender, System.EventArgs e)

{

  this.axAnimation1.Open(Application.StartupPath +@"\FILECOPY.AVI");

}

这样当窗体加载的时候就会自动的播放这一小段AVI文件了.其实,这个问题并不是很难,主要是本人对COM组件并不是特别熟悉的过.只要熟悉这些组件的功能,以及运行的原理,势必会大大的提高我们的编程的效率。

1、基本属性  URL 指定媒体位置,本机或网络地址 例如:axWindowsMediaPlayer1.URL = @"f:\aa.mp3"; uiMode 播放器界面模式,可为Full, Mini, None, Invisible ;Full:有下面的控制条; None:只有播放部份没有控制条 例如:axWindowsMediaPlayer1.uiMode = "Invisible"; playState 播放状态,1=停止,2=暂停,3=播放,6=正在缓冲,9=正在连接,10=准备就绪 enableContextMenu 启用/禁用右键菜单 fullScreen 是否全屏显示 stretchToFit 非全屏状态时是否伸展到最佳大小 2、播放器基本控制 Ctlcontrols.play(); 播放 Ctlcontrols.pause(); 暂停 Ctlcontrols.stop(); 停止 Ctlcontrols.currentPosition 当前进度 Ctlcontrols.currentPositionString 当前进度,字符串格式。如“00:23” Ctlcontrols.fastForward(); 快进 Ctlcontrols.fastReverse(); 快退 Ctlcontrols.next(); 下一曲 Ctlcontrols.previous(); 上一曲 3、播放器基本设置 settings.volume 音量,0-100 settings.balance 声道,通过它应该可以进行立体声、左声道、右声道的控制。 settings.autoStart 是否自动播放 settings.mute 是否静音 settings.playCount 播放次数 settings.rate 播放速度 4、当前媒体属性 currentMedia.duration 媒体总长度 currentMedia.durationString 媒体总长度,字符串格式。如“03:24” currentMedia.getItemInfo(const string) 获取当前媒体信息"Title"=媒体标题,"Author"=艺术家,"Copyright"=版权信息,"Description"=媒体内容描述,"Duration"=持续时间(秒),"FileSize"=文件大小,"FileType"=文件类型,"sourceURL"=原始地址 currentMedia.setItemInfo(const string) 通过属性名设置媒体信息 currentMedia.name 同 currentMedia.getItemInfo("Title")

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧