• 调用DirectX进行简单的多媒体编程系列(三)


    以上把基本的类写好了,下面就可以开始编写前台代码了。先来个截图


     直接上代码吧

     using System;

    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using QBAudioLib;


    namespace QBAudio
    {
        
    public partial class Form2 : Form
        {
            QBAudioCtrl qbCtrl;
            DeviceStatus devStauts;
            PlayFlags thisFlags;

            
    public Form2()
            {
                InitializeComponent();

            }

            
    private void Form2_Load(object sender, EventArgs e)//初始化
            {
                
    //获得所有的音频设备
                List<DeviceInfo> devInfo = QBDeviceHelper.GetDeviceList();
                
    foreach (DeviceInfo dev in devInfo)
                {
                    cBox_Devices.Items.Add(dev.DevId);
                }

                
    this.thisFlags = PlayFlags.Default;
            }




            
    private void btn_play_Click(object sender, EventArgs e)//播放
            {
                
    try
                {
                    qbCtrl.Dev_Play(
    this.thisFlags);
                    devStauts 
    = qbCtrl.GetDeviceStatus();
                    lbl_status.Text 
    = "playing:" + devStauts.isPlaying.ToString() + "---looping:" + devStauts.isLooping + "---Terminated:" + devStauts.isTerminated;
                }
                
    catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            
    private void btn_stop_Click(object sender, EventArgs e)//停止
            {
                
    try
                {
                    qbCtrl.Dev_Stop();
                    devStauts 
    = qbCtrl.GetDeviceStatus();
                    lbl_status.Text 
    = "playing:" + devStauts.isPlaying.ToString() + "---looping:" + devStauts.isLooping + "---Terminated:" + devStauts.isTerminated;
                }
                
    catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            
    private void btn_File_Click(object sender, EventArgs e)//选择播放文件
            {
                OpenFileDialog filedg 
    = new OpenFileDialog();
                filedg.Filter 
    = "音视频文件(*.wav)|*.wav";
                
    if (filedg.ShowDialog() == DialogResult.OK)
                {
                    
    if (filedg.FileName != "" || filedg.FileName != string.Empty)
                    {
                        txt_File.Text 
    = filedg.FileName;
                    }
                }
            }

            
    private void cBox_Devices_SelectedIndexChanged(object sender, EventArgs e)//选择声卡
            {
                
    try
                {
                    
    //thisDev = (DeviceInfo)cBox_Devices.SelectedItem;
                    Guid devID = (Guid)cBox_Devices.SelectedItem;
                    
    string fileName = txt_File.Text.Trim();
                    
    if (fileName == null || fileName == string.Empty)
                    {
                        MessageBox.Show(
    "请选择播放的文件...");
                        
    return;
                    }
                    qbCtrl 
    = new QBAudioCtrl(devID, fileName);
                    devStauts 
    = qbCtrl.GetDeviceStatus();
                    lbl_status.Text 
    = "playing:" + devStauts.isPlaying.ToString() + "---looping:" + devStauts.isLooping + "---Terminated:" + devStauts.isTerminated;
                }
                
    catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

            }


            
    private void btn_pause_Click(object sender, EventArgs e)//暂停
            {
                
    try
                {
                    qbCtrl.Dev_Dispose();
                }
                
    catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            
    private void radioButton1_CheckedChanged(object sender, EventArgs e)//设置正常播放
            {
                
    if (radioButton1.Checked)
                {
                    thisFlags 
    = PlayFlags.Default;
                    btn_play_Click(sender, e);
                }
            }

            
    private void radioButton2_CheckedChanged(object sender, EventArgs e)//设置循环播放
            {
                
    if (radioButton2.Checked)
                {
                    thisFlags 
    = PlayFlags.Looping;
                    btn_play_Click(sender, e);
                }
            }
        }
    }
  • 相关阅读:
    rhel5.4 x64安装apache http server2.2.27,并创建自动启服务
    解决BEA-000438 Unable to load performance pack.
    为aix系统挂载iso镜像-命令
    IBM小型机创建RAID
    linux下使用parted工具划分大于2T的分区
    linux下的SElinux
    日立HDS AMS2100存储的调试
    rhel创建yum源
    rfid安全简介
    安卓模拟器抓包
  • 原文地址:https://www.cnblogs.com/xnxylf/p/1616877.html
Copyright © 2020-2023  润新知