如何播放RealPlayer文件
我们先从工具栏中添加一个COM组件
RealPlayer G2 Control
当然 你机子中得装有RealPlayer
然后就开始画界面吧
再来看下代码
private void button1_Click(object sender, System.EventArgs e)
{//浏览RealPlayer文件
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
this.axRealAudio1.Source=this.openFileDialog1.FileName;
}
}
private void button2_Click(object sender, System.EventArgs e)
{//播放RealPlayer文件
if(this.openFileDialog1.FileName.Length>0)
{
if(this.axRealAudio1.CanPlay())
{
this.axRealAudio1.DoPlay();
}
}
else
{
MessageBox.Show("请选择RealPlayer文件!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void button4_Click(object sender, System.EventArgs e)
{//暂停播放RealPlayer文件
if(this.openFileDialog1.FileName.Length>0)
{
if(this.axRealAudio1.CanPlayPause())
{
this.axRealAudio1.DoPlayPause();
}
}
else
{
MessageBox.Show("请选择RealPlayer文件!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void button5_Click(object sender, System.EventArgs e)
{//停止播放RealPlayer文件
if(this.openFileDialog1.FileName.Length>0)
{
if(this.axRealAudio1.CanStop())
{
this.axRealAudio1.DoStop();
}
}
else
{
MessageBox.Show("请选择RealPlayer文件!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void button3_Click(object sender, System.EventArgs e)
{//有声无声设置
if(this.openFileDialog1.FileName.Length>0)
{
if(this.button3.Text=="无声")
{
this.axRealAudio1.SetMute(true);
this.button3.Text="有声";
}
else
{
this.axRealAudio1.SetMute(false);
this.button3.Text="无声";
}
}
else
{
MessageBox.Show("请选择RealPlayer文件!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}