コード例 #1
0
        public CVoiceConfigForm()
        {
            InitializeComponent();
            m_openFileDialog = new OpenFileDialog()
            {
                Title  = "选择音频文件",
                Filter = "音频文件(*.wav)|*.wav|(*.mp3)|*.mp3"
            };

            string path    = string.Empty;
            bool   enabled = false;

            VoiceXmlHelper.ReadFromXML(out path, out enabled);
            this.textBox_FileName.Text  = Path.GetFileName(m_strCurrentPathAndFileName);
            this.chkEnabled.Checked     = enabled;
            m_strCurrentPathAndFileName = path;

            // 是否正在播放音频文件
            this.btnStop.Enabled = CVoicePlayer.Instance.IsCurrentPlay();

            UpdateFileAndPathTextBox();

            // 添加事件响应
            this.FormClosing += new FormClosingEventHandler(EHFormClosing);
        }
コード例 #2
0
        /// <summary>
        /// 循环播放当前配置文件中的音频文件,告警信息时候调用
        /// </summary>
        public void Play()
        {
            try
            {
                string source  = string.Empty;
                bool   enabled = false;
                VoiceXmlHelper.ReadFromXML(out source, out enabled);

                if (File.Exists(source) && enabled)
                {
                    m_currentPlayer.OpenFile(source, TStreamFormat.sfAutodetect);
                    // 循环播放
                    TStreamInfo info = new TStreamInfo();
                    m_currentPlayer.GetStreamInfo(ref info);

                    TStreamTime time = new TStreamTime();
                    time.sec = 0;
                    TStreamTime timeEnd = new TStreamTime();
                    timeEnd.sec = info.Length.sec;
                    m_currentPlayer.PlayLoop(TTimeFormat.tfSecond, ref time, TTimeFormat.tfSecond, ref timeEnd, Int32.MaxValue, true);
                    m_bIsCurrentFromWarningInfo = true;
                    //Play(source);
                }
            }
            catch (Exception exp)
            {
                System.Diagnostics.Debug.WriteLine(exp.Message);
            }
            finally
            {
            }
        }