Example #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);
        }
Example #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
            {
            }
        }
Example #3
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            //string path = this.textBox_FileName.Text.Trim();
            string path    = m_strCurrentPathAndFileName;
            bool   enabled = this.chkEnabled.Checked;

            if (String.IsNullOrEmpty(path))
            {
                MessageBox.Show(String.Format("音频文件名不能为空!"));
                return;
            }
            if (!File.Exists(path))
            {
                MessageBox.Show(String.Format("音频文件{0}不存在!", path));
                return;
            }

            if (VoiceXmlHelper.WriteToXML(path, enabled))
            {
                MessageBox.Show("保存成功!");
            }
        }
Example #4
0
        public static void ReadFromXML(out string path, out bool enabled)
        {
            string filename = "Config/sounds.xml";

            path    = string.Empty;
            enabled = false;
            if (File.Exists(filename))
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(filename);
                var root = xmlDoc.DocumentElement;

                XmlNode singleChild = xmlDoc.SelectSingleNode("sound/enable");
                enabled = Boolean.Parse(singleChild.InnerText);

                singleChild = xmlDoc.SelectSingleNode("sound/source");
                path        = singleChild.InnerText.ToString();
            }
            else
            {
                VoiceXmlHelper.WriteToXML("default.wav", true);
                ReadFromXML(out path, out enabled);
            }
        }