我们先从工具栏中添加一个COM组件

RealPlayer G2 Control

当然 你机子中得装有RealPlayer

然后就开始画界面吧

如何播放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);
            }        
        }

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2021-11-10
  • 2021-06-24
猜你喜欢
  • 2021-07-07
  • 2022-02-16
  • 2022-12-23
  • 2021-08-16
  • 2021-08-09
  • 2021-12-22
相关资源
相似解决方案