.net framework里有了许多COM组件,我们可以根据应用程序的需要来使用这些组件,不用自己再去 “造轮子”了。<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
第一个示例是来制作一个VCD播放器.这里我使用了Windows自带的Media Play来播放多媒体文件。
![06121401.JPG](https://i-blog.csdnimg.cn/blog_migrate/adf26b8180cf8073e80559af086bd531.jpeg)
选择‘工具箱’—‘组件’,右击,选择‘添加/移除项’—‘COM组件‘(如果你是第一次使用Windows Media Play控件,在列表中是没有这个控件的,可以在系统文件夹下找到,一般是在C:/Windows/System32/msdxm.ocx,把这个控件加入到控件列表中,就可以使用了。
代码如下:
using
System;
using
System.Drawing;
using
System.Collections;
using
System.ComponentModel;
using
System.Windows.Forms;
using
System.Data;
![None.gif](/Images/OutliningIndicators/None.gif)
namespace
MPlayDemo
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
publicclassForm1:System.Windows.Forms.Form
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
privateAxMediaPlayer.AxMediaPlayeraxMediaPlayer1;
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
publicForm1()
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
InitializeComponent();
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
#region
privatevoidInitializeComponent()
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axMediaPlayer1=newAxMediaPlayer.AxMediaPlayer();
//
//axMediaPlayer1
//
this.axMediaPlayer1.Dock=System.Windows.Forms.DockStyle.Top;
this.axMediaPlayer1.Location=newSystem.Drawing.Point(0,0);
this.axMediaPlayer1.Name="axMediaPlayer1";
this.axMediaPlayer1.OcxState=((System.Windows.Forms.AxHost.State)(resources.GetObject("axMediaPlayer1.OcxState")));
this.axMediaPlayer1.Size=newSystem.Drawing.Size(488,376);
this.axMediaPlayer1.TabIndex=0;
}
#endregion
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnPlay_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.axMediaPlayer1.FileName.Trim()=="")
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"请选择要播放的文件!!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
this.axMediaPlayer1.Play();
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnPause_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.axMediaPlayer1.FileName.Trim()=="")
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"请选择要播放的文件!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
this.axMediaPlayer1.Pause();
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnStop_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.axMediaPlayer1.FileName.Trim()=="")
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"请选择要播放的文件","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
this.axMediaPlayer1.Stop();
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidmenuItem3_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
Application.Exit();
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidmenuItem2_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.openFileDialog1.ShowDialog();
stringstrFileName=this.openFileDialog1.FileName;
if(strFileName.Trim()=="")
return;
this.axMediaPlayer1.FileName=strFileName;
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidmenuItem4_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axMediaPlayer1.AboutBox();
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidmenuItem5_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axMediaPlayer1.FastForward();
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
}
第二个示例是制作一个DVD播放器:
![06121402.JPG](https://i-blog.csdnimg.cn/blog_migrate/86b788910c6a4e5aca682f4f7f270771.jpeg)
选择‘工具箱’—‘组件’,右击,选择‘添加/移除项’—‘COM组件‘把“MSWebDVD
”这个控件加入到控件列表中,就可以使用了。
代码如下:
using
System;
using
System.Drawing;
using
System.Collections;
using
System.ComponentModel;
using
System.Windows.Forms;
using
System.Data;
![None.gif](/Images/OutliningIndicators/None.gif)
namespace
DVDPlayDemo
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
publicclassForm1:System.Windows.Forms.Form
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
privateAxMSWEBDVDLib.AxMSWebDVDaxMSWebDVD1;
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
Windows#regionWindows
privatevoidInitializeComponent()
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axMSWebDVD1=newAxMSWEBDVDLib.AxMSWebDVD();
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
//
//axMSWebDVD1
//
this.axMSWebDVD1.Dock=System.Windows.Forms.DockStyle.Top;
this.axMSWebDVD1.Enabled=true;
this.axMSWebDVD1.Location=newSystem.Drawing.Point(0,0);
this.axMSWebDVD1.Name="axMSWebDVD1";
this.axMSWebDVD1.OcxState=((System.Windows.Forms.AxHost.State)(resources.GetObject("axMSWebDVD1.OcxState")));
this.axMSWebDVD1.Size=newSystem.Drawing.Size(504,320);
this.axMSWebDVD1.TabIndex=0;
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
#endregion
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnPlay_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
try
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axMSWebDVD1.Play();
}
catch(System.Exceptionex)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(ex.Message.ToString());
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnPause_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
try
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axMSWebDVD1.Pause();
}
catch(System.Exceptionex)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(ex.Message.ToString());
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnStop_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
try
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axMSWebDVD1.Stop();
}
catch(System.Exceptionex)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(ex.Message.ToString());
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnOut_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
try
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axMSWebDVD1.Eject();
}
catch(System.Exceptionex)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(ex.Message.ToString());
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
}
第三个示例是制作一个Flash播放器。选择‘工具箱’—‘组件’,右击,选择‘添加/移除项’—‘COM组件‘把“Shockwave Flash Object”这个控件加入到控件列表中,就可以使用了。
![06121403.JPG](https://i-blog.csdnimg.cn/blog_migrate/6c1b36d699ef4c414ed8f9c4b0cceab9.jpeg)
using
System;
using
System.Drawing;
using
System.Collections;
using
System.ComponentModel;
using
System.Windows.Forms;
using
System.Data;
![None.gif](/Images/OutliningIndicators/None.gif)
namespace
FlashPlayDemo
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
publicclassForm1:System.Windows.Forms.Form
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privateAxShockwaveFlashObjects.AxShockwaveFlashaxShockwaveFlash1;
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
#region
privatevoidInitializeComponent()
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
this.axShockwaveFlash1=newAxShockwaveFlashObjects.AxShockwaveFlash();
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
//
//axShockwaveFlash1
//
this.axShockwaveFlash1.Dock=System.Windows.Forms.DockStyle.Top;
this.axShockwaveFlash1.Enabled=true;
this.axShockwaveFlash1.Location=newSystem.Drawing.Point(0,0);
this.axShockwaveFlash1.Name="axShockwaveFlash1";
this.axShockwaveFlash1.OcxState=((System.Windows.Forms.AxHost.State)(resources.GetObject("axShockwaveFlash1.OcxState")));
this.axShockwaveFlash1.Size=newSystem.Drawing.Size(680,312);
this.axShockwaveFlash1.TabIndex=0;
}
#endregion
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidmenuItem2_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axShockwaveFlash1.Movie=this.openFileDialog1.FileName;
this.Text="播放的是-"+this.openFileDialog1.FileName;
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnPlay_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.openFileDialog1.FileName.Length>0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axShockwaveFlash1.Play();
}
else
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"请选择文件!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnStop_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.openFileDialog1.FileName.Length>0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axShockwaveFlash1.Stop();
}
else
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"请选择文件!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnFisrt_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.openFileDialog1.FileName.Length>0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axShockwaveFlash1.Rewind();
}
else
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"请选择文件!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnLast_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.openFileDialog1.FileName.Length>0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axShockwaveFlash1.Back();
}
else
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"请选择文件!!!","信息提示“,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnNext_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.openFileDialog1.FileName.Length>0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axShockwaveFlash1.Forward();
}
else
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"请选择文件!!!","信息提示”,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
}
第四个示例是制作一个RealPlay播放器。选择‘工具箱’—‘组件’,右击,选择‘添加/移除项’—‘COM组件‘,把“RealPlayer G2 Control”这个控件加入到控件列表中,就可以使用了。
![06121404.JPG](https://i-blog.csdnimg.cn/blog_migrate/e5f680514ec6f52f2994eede8958723d.jpeg)
为了简单起见,就直接使用它的控制面板了,代码如下:
using
System;
using
System.Drawing;
using
System.Collections;
using
System.ComponentModel;
using
System.Windows.Forms;
using
System.Data;
![None.gif](/Images/OutliningIndicators/None.gif)
namespace
RealPlayDemo
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
publicclassForm1:System.Windows.Forms.Form
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
privateAxRealAudioObjects.AxRealAudioaxRealAudio1;
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
#region
privatevoidInitializeComponent()
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
this.axRealAudio1=newAxRealAudioObjects.AxRealAudio();
}
#endregion
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidmenuItem2_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axRealAudio1.Source=this.openFileDialog1.FileName;
this.axRealAudio1.DoPlay();
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidmenuItem3_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
Application.Exit();
}
}
}
最后一个示例是对第一个Windows Media Play播放器的扩展,用它来制作一个Mp3播放器。选择‘工具箱’—‘组件’,右击,选择‘添加/移除项’—‘COM组件‘,把“Windows Media Play”这个控件加入到控件列表中,就可以使用了。
![06121405.JPG](https://i-blog.csdnimg.cn/blog_migrate/4d5294df8e165d05ace9d94c9f5edab4.jpeg)
代码如下:
using
System;
using
System.Drawing;
using
System.Collections;
using
System.ComponentModel;
using
System.Windows.Forms;
using
System.Data;
using
System.IO;
![None.gif](/Images/OutliningIndicators/None.gif)
namespace
MP3PlayerDemo
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
publicclassForm1:System.Windows.Forms.Form
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
privateAxMediaPlayer.AxMediaPlayeraxMediaPlayer1;
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
#region
privatevoidInitializeComponent()
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axMediaPlayer1=newAxMediaPlayer.AxMediaPlayer();
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
#endregion
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidmenuItem3_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
Application.Exit();
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidmenuItem2_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.listView1.Items.Clear();
string[]FileNames=this.openFileDialog1.FileNames;
foreach(stringfNameinFileNames)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
System.IO.FileInfofInfo=newFileInfo(fName);
floatfSize=(float)fInfo.Length/(1024*1024);
this.axMediaPlayer1.FileName=fName;
this.axMediaPlayer1.Stop();
stringauthor=this.axMediaPlayer1.GetMediaInfoString(MediaPlayer.MPMediaInfoType.mpClipAuthor);
stringshortFileName=fName.Substring(fName.LastIndexOf("//")+1);
shortFileName=shortFileName.Substring(0,shortFileName.Length-4);
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
string[]subItem=
{shortFileName,author,fSize.ToString().Substring(0,4)+"M",fName};
ListViewItemitem=newListViewItem(subItem);
this.listView1.Items.Add(item);
this.listView1.Items[0].Selected=true;
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnPlay_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.listView1.Items.Count>0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.listView1.SelectedItems.Count>0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
intpos=this.listView1.SelectedItems[0].Index;
stringfName=this.listView1.Items[pos].SubItems[3].Text;
this.axMediaPlayer1.FileName=fName;
this.axMediaPlayer1.Play();
}
else
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"ÇëÑ¡ÔñÒª²¥•ÅµÄ¸èÇú!!!","ÐÅÏ¢Ìáʾ",MessageBoxButtons.OK,MessageBoxIcon.Information);
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnPause_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.axMediaPlayer1.FileName.Length>0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axMediaPlayer1.Pause();
}
else
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"请选择要播放的歌曲!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnStop_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.axMediaPlayer1.FileName.Length>0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.axMediaPlayer1.Stop();
}
else
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"请选择要播放的歌曲!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnLast_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.listView1.Items.Count>0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.listView1.SelectedItems.Count>0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
intpos=this.listView1.SelectedItems[0].Index;
if(pos>0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.listView1.Items[pos-1].Selected=true;
stringfName=this.listView1.Items[pos-1].SubItems[3].Text;
this.axMediaPlayer1.FileName=fName;
this.axMediaPlayer1.Play();
}
else
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"已经是第一首歌曲了!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
}
else
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"请选择要播放的歌曲!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
privatevoidbtnNext_Click(objectsender,System.EventArgse)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.listView1.Items.Count>0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
if(this.listView1.SelectedItems.Count>0)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
intpos=this.listView1.SelectedItems[0].Index;
if(pos<this.listView1.Items.Count-1)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
this.listView1.Items[pos+1].Selected=true;
stringfName=this.listView1.Items[pos+1].SubItems[3].Text;
this.axMediaPlayer1.FileName=fName;
this.axMediaPlayer1.Play();
}
else
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"已经是最后一首歌曲了!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
}
else
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
MessageBox.Show(this,"请选择要播放的歌曲!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
}
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)