示例#1
0
        private void ShutDown(string errmsg)
        {
            bool err = !String.IsNullOrEmpty(errmsg);

            if (err)
            {
                _reasonToStop = ReasonToFinishPlaying.DeviceLost;
            }

            if (IsFileSource && !err)
            {
                _reasonToStop = ReasonToFinishPlaying.EndOfStreamReached;
            }

            if (_afr != null && _afr.IsOpen)
            {
                try
                {
                    _afr.Dispose(); //calls close
                }
                catch (Exception ex)
                {
                    MainForm.LogExceptionToFile(ex, "FFMPEG");
                }
            }

            if (AudioFinished != null)
            {
                AudioFinished(this, _reasonToStop);
            }
        }
示例#2
0
        private void ShutDown(string errmsg)
        {
            bool err = !string.IsNullOrEmpty(errmsg);

            if (err)
            {
                _reasonToStop = ReasonToFinishPlaying.DeviceLost;
            }

            if (IsFileSource && !err)
            {
                _reasonToStop = ReasonToFinishPlaying.EndOfStreamReached;
            }

            if (_afr != null && _afr.IsOpen)
            {
                try
                {
                    _afr.Dispose(); //calls close
                }
                catch (Exception ex)
                {
                    Logger.LogExceptionToFile(ex, "FFMPEG");
                }
            }

            AudioFinished?.Invoke(this, new PlayingFinishedEventArgs(_reasonToStop));
        }
示例#3
0
        private void Test_Click(object sender, EventArgs e)
        {
            btnTest.Enabled = false;

            string res = "OK";

            try
            {
                Program.FfmpegMutex.WaitOne();
                var    afr    = new AudioFileReader();
                string source = cmbFFMPEGURL.Text;
                int    i      = source.IndexOf("://", StringComparison.Ordinal);
                if (i > -1)
                {
                    source = source.Substring(0, i).ToLower() + source.Substring(i);
                }

                afr.Timeout         = Mic.settings.timeout;
                afr.AnalyzeDuration = (int)numAnalyseDuration.Value;
                afr.Open(source);
                afr.ReadAudioFrame();
                Mic.settings.channels = afr.Channels;
                Mic.settings.samples  = afr.SampleRate;
                Mic.settings.bits     = 16;

                afr.Dispose();
                afr = null;
            }
            catch (Exception ex)
            {
                res = ex.Message;
            }
            finally
            {
                try
                {
                    Program.FfmpegMutex.ReleaseMutex();
                }
                catch (ObjectDisposedException)
                {
                    //can happen on shutdown
                }
            }
            MessageBox.Show(res);

            btnTest.Enabled = true;
        }
示例#4
0
        private void ShutDown(string errmsg)
        {
            bool err = !String.IsNullOrEmpty(errmsg);

            if (err)
            {
                _reasonToStop = ReasonToFinishPlaying.DeviceLost;
            }

            if (IsFileSource && !err)
            {
                _reasonToStop = ReasonToFinishPlaying.EndOfStreamReached;
            }

            try
            {
                _afr.Dispose();//calls close!
            }
            catch (Exception ex)
            {
                MainForm.LogExceptionToFile(ex);
            }

            // release events
            if (_stopEvent != null)
            {
                _stopEvent.Close();
                _stopEvent.Dispose();
                _stopEvent = null;
            }
            _stopEvent = null;

            if (AudioFinished != null)
            {
                AudioFinished(this, _reasonToStop);
            }

            if (_waveProvider != null)
            {
                if (_waveProvider.BufferedBytes > 0)
                {
                    _waveProvider.ClearBuffer();
                }
            }

            _isrunning = false;
        }
示例#5
0
        private void Test_Click(object sender, EventArgs e)
        {
            btnTest.Enabled = false;

            string res = "OK";
            try
            {
                Program.FfmpegMutex.WaitOne();
                var afr = new AudioFileReader();
                string source = cmbFFMPEGURL.Text;
                int i = source.IndexOf("://", StringComparison.Ordinal);
                if (i > -1)
                {
                    source = source.Substring(0, i).ToLower() + source.Substring(i);
                }

                afr.Timeout = Mic.settings.timeout;
                afr.AnalyzeDuration = (int)numAnalyseDuration.Value;
                afr.Open(source);
                afr.ReadAudioFrame();
                Mic.settings.channels = afr.Channels;
                Mic.settings.samples = afr.SampleRate;
                Mic.settings.bits = 16;

                afr.Dispose();
                afr = null;
            }
            catch (Exception ex)
            {
                res = ex.Message;
            }
            finally
            {
                try
                {
                    Program.FfmpegMutex.ReleaseMutex();
                }
                catch (ObjectDisposedException)
                {
                    //can happen on shutdown
                }
            }
            MessageBox.Show(res);

            btnTest.Enabled = true;
        }