.net framework里有了许多COM组件,我们可以根据应用程序的需要来使用这些组件,不用自己再去 “造轮子”了。
第一个示例是来制作一个VCD播放器.这里我使用了Windows自带的Media Play来播放多媒体文件。
06121401.JPG
选择‘工具箱’—‘组件’,右击,选择‘添加/移除项’—‘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;
namespace MPlayDemo
{
public class Form1 : System.Windows.Forms.Form
{
private AxMediaPlayer.AxMediaPlayer axMediaPlayer1;
public Form1()
{
InitializeComponent();
}
private void btnPlay_Click(object sender, System.EventArgs e)
{
if(this.axMediaPlayer1.FileName.Trim()=="")
{
MessageBox.Show(this," 请选择要播放的文件!!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
this.axMediaPlayer1.Play();
}
private void btnPause_Click(object sender, System.EventArgs e)
{
if(this.axMediaPlayer1.FileName.Trim()=="")
{
MessageBox.Show(this," 请选择要播放的文件!!!"," 信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
this.axMediaPlayer1.Pause();
}
private void btnStop_Click(object sender, System.EventArgs e)
{
if(this.axMediaPlayer1.FileName.Trim()=="")
{
MessageBox.Show(this,"请选择要播放的文件","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
this.axMediaPlayer1.Stop();
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
this.openFileDialog1.ShowDialog();
string strFileName = this.openFileDialog1.FileName;
if(strFileName.Trim()=="")
return;
this.axMediaPlayer1.FileName = strFileName;
}
private void menuItem4_Click(object sender, System.EventArgs e)
{
this.axMediaPlayer1.AboutBox();
}
private void menuItem5_Click(object sender, System.EventArgs e)
{
this.axMediaPlayer1.FastForward();
}
}
第二个示例是制作一个DVD播放器:
06121402.JPG
选择‘工具箱’—‘组件’,右击,选择‘添加/移除项’—‘COM组件‘把“MSWebDVD
”这个控件加入到控件列表中,就可以使用了。
代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DVDPlayDemo
{
public class Form1 : System.Windows.Forms.Form
{
private AxMSWEBDVDLib.AxMSWebDVD axMSWebDVD1;
Windows
private void btnPlay_Click(object sender, System.EventArgs e)
{
try
{
this.axMSWebDVD1.Play();
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void btnPause_Click(object sender, System.EventArgs e)
{
try
{
this.axMSWebDVD1.Pause();
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void btnStop_Click(object sender, System.EventArgs e)
{
try
{
this.axMSWebDVD1.Stop();
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void btnOut_Click(object sender, System.EventArgs e)
{
try
{
this.axMSWebDVD1.Eject();
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
}
第三个示例是制作一个Flash播放器。选择‘工具箱’—‘组件’,右击,选择‘添加/移除项’—‘COM组件‘把“Shockwave Flash Object”这个控件加入到控件列表中,就可以使用了。
06121403.JPG
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace FlashPlayDemo
{
public class Form1 : System.Windows.Forms.Form
{
private AxShockwaveFlashObjects.AxShockwaveFlash axShockwaveFlash1;
private void menuItem2_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
this.axShockwaveFlash1.Movie = this.openFileDialog1.FileName;
this.Text = "播放的是-"+this.openFileDialog1.FileName;
}
}
private void btnPlay_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.FileName.Length>0)
{
this.axShockwaveFlash1.Play();
}
else
{
MessageBox.Show(this,"请选择文件!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void btnStop_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.FileName.Length>0)
{
this.axShockwaveFlash1.Stop();
}
else
{
MessageBox.Show(this,"请选择文件!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void btnFisrt_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.FileName.Length>0)
{
this.axShockwaveFlash1.Rewind();
}
else
{
MessageBox.Show(this,"请选择文件!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void btnLast_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.FileName.Length>0)
{
this.axShockwaveFlash1.Back();
}
else
{
MessageBox.Show(this,"请选择文件!!!","信息提示“,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void btnNext_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.FileName.Length>0)
{
this.axShockwaveFlash1.Forward();
}
else
{
MessageBox.Show(this,"请选择文件!!!","信息提示”,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
}
第四个示例是制作一个RealPlay播放器。选择‘工具箱’—‘组件’,右击,选择‘添加/移除项’—‘COM组件‘,把“RealPlayer G2 Control”这个控件加入到控件列表中,就可以使用了。
06121404.JPG
为了简单起见,就直接使用它的控制面板了,代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace RealPlayDemo
{
public class Form1 : System.Windows.Forms.Form
{
private AxRealAudioObjects.AxRealAudio axRealAudio1;
private void menuItem2_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
this.axRealAudio1.Source = this.openFileDialog1.FileName;
this.axRealAudio1.DoPlay();
}
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}
最后一个示例是对第一个Windows Media Play播放器的扩展,用它来制作一个Mp3播放器。选择‘工具箱’—‘组件’,右击,选择‘添加/移除项’—‘COM组件‘,把“Windows Media Play”这个控件加入到控件列表中,就可以使用了。
06121405.JPG
代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace MP3PlayerDemo
{
public class Form1 : System.Windows.Forms.Form
{
private AxMediaPlayer.AxMediaPlayer axMediaPlayer1;
private void menuItem3_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
this.listView1.Items.Clear();
string[] FileNames = this.openFileDialog1.FileNames;
foreach(string fName in FileNames)
{
System.IO.FileInfo fInfo = new FileInfo(fName);
float fSize = (float)fInfo.Length/(1024*1024);
this.axMediaPlayer1.FileName = fName;
this.axMediaPlayer1.Stop();
string author = this.axMediaPlayer1.GetMediaInfoString(MediaPlayer.MPMediaInfoType.mpClipAuthor);
string shortFileName = fName.Substring(fName.LastIndexOf("\\")+1);
shortFileName = shortFileName.Substring(0,shortFileName.Length-4);
string[] subItem = {shortFileName,author,fSize.ToString().Substring(0,4)+"M",fName};
ListViewItem item = new ListViewItem(subItem);
this.listView1.Items.Add(item);
this.listView1.Items[0].Selected = true;
}
}
}
private void btnPlay_Click(object sender, System.EventArgs e)
{
if(this.listView1.Items.Count>0)
{
if(this.listView1.SelectedItems.Count>0)
{
int pos = this.listView1.SelectedItems[0].Index;
string fName = this.listView1.Items[pos].SubItems[3].Text;
this.axMediaPlayer1.FileName = fName;
this.axMediaPlayer1.Play();
}
else
{
MessageBox.Show(this,"ÇëÑ¡ÔñÒª²¥•ŵĸèÇú!!!","ÐÅÏ¢Ìáʾ",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
private void btnPause_Click(object sender, System.EventArgs e)
{
if(this.axMediaPlayer1.FileName.Length>0)
{
this.axMediaPlayer1.Pause();
}
else
{
MessageBox.Show(this,"请选择要播放的歌曲!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void btnStop_Click(object sender, System.EventArgs e)
{
if(this.axMediaPlayer1.FileName.Length>0)
{
this.axMediaPlayer1.Stop();
}
else
{
MessageBox.Show(this," 请选择要播放的歌曲!!!"," 信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void btnLast_Click(object sender, System.EventArgs e)
{
if(this.listView1.Items.Count>0)
{
if(this.listView1.SelectedItems.Count>0)
{
int pos = this.listView1.SelectedItems[0].Index;
if(pos>0)
{
this.listView1.Items[pos-1].Selected = true;
string fName = this.listView1.Items[pos-1].SubItems[3].Text;
this.axMediaPlayer1.FileName = fName;
this.axMediaPlayer1.Play();
}
else
{
MessageBox.Show(this,"已经是第一首歌曲了!!!"," 信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
else
{
MessageBox.Show(this," 请选择要播放的歌曲!!!"," 信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
private void btnNext_Click(object sender, System.EventArgs e)
{
if(this.listView1.Items.Count>0)
{
if(this.listView1.SelectedItems.Count>0)
{
int pos = this.listView1.SelectedItems[0].Index;
if(pos<this.listView1.Items.Count-1)
{
this.listView1.Items[pos+1].Selected = true;
string fName = this.listView1.Items[pos+1].SubItems[3].Text;
this.axMediaPlayer1.FileName = fName;
this.axMediaPlayer1.Play();
}
else
{
MessageBox.Show(this,"已经是最后一首歌曲了!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
else
{
MessageBox.Show(this," 请选择要播放的歌曲!!!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
}
}
本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2006/12/14/592557.html,如需转载请自行联系原作者
微信关注我们
原文链接:https://yq.aliyun.com/articles/342957
转载内容版权归作者及来源网站所有!
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
相关文章
发表评论
资源下载
更多资源优质分享App
近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。
Mario
马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。
Oracle
Oracle Database,又名Oracle RDBMS,或简称Oracle。是甲骨文公司的一款关系数据库管理系统。它是在数据库领域一直处于领先地位的产品。可以说Oracle数据库系统是目前世界上流行的关系数据库管理系统,系统可移植性好、使用方便、功能强,适用于各类大、中、小、微机环境。它是一种高效率、可靠性好的、适应高吞吐量的数据库方案。
Apache Tomcat
Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。因为Tomcat 技术先进、性能稳定,而且免费,因而深受Java 爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web 应用服务器。