Exemplo n.º 1
0
 public void Play(string soundFilePath)
 {
     ThreadUtils.StartBackgroundThread(
         () =>
     {
         Thread.Sleep(100);
         PlayingStopped.RaiseEvent(this);
     });
 }
Exemplo n.º 2
0
        private void UnixPlayThread(object state)
        {
            if (_unixPlayStopEvent.WaitOne(0))
            {
                return;
            }
            Stream      stream = null;
            AudioDevice dev    = null;

            try
            {
                lock (s_playSync)
                {
                    dev          = AudioDevice.CreateAlsaDevice(_latency);
                    stream       = ReadFile((string)state);
                    _unixWavData = new WavData(_logger, stream, _unixPlayStopEvent);
                }
                _unixWavData.Setup(dev);
                _unixWavData.Play(dev);
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                _logger.LogError(Message.SoundPlayError, ex, (string)state);
            }
            finally
            {
                if (dev != null)
                {
                    dev.Dispose();
                }
                if (stream != null)
                {
                    stream.Close();
                }
                if (_unixWavData == null || !_unixWavData.IsStopped)
                {
                    PlayingStopped.RaiseEvent(this);
                }
            }
        }
Exemplo n.º 3
0
 private void WinPlayThread(object state)
 {
     try
     {
         using (var stream = ReadFile((string)state))
         {
             _winPlayer.Stream = stream;
             var time = TimeSpan.FromMilliseconds(
                 (_winPlayer.Stream.Length - 44.0) / (24000 * (16 / 8)) / 1 * 1000 + 100);
             _winPlayer.Play();
             Thread.Sleep(time);
         }
         PlayingStopped.RaiseEvent(this);
     }
     catch (ThreadAbortException)
     {
     }
     catch (Exception ex)
     {
         _logger.LogError(Message.SoundPlayError, ex, (string)state);
     }
 }
Exemplo n.º 4
0
 private void PlayThread(object state)
 {
     try
     {
         Stop();
         _logger.LogVerbose(Message.SoundSpeexStartPlay, (string)state ?? String.Empty);
         var startInfo = new ProcessStartInfo(PLAY_COMMAND, (string)state ?? String.Empty)
         {
             CreateNoWindow         = true,
             UseShellExecute        = false,
             RedirectStandardOutput = true,
             RedirectStandardError  = true
         };
         using (_playCommand = Process.Start(startInfo))
         {
             var res = ProcessHelper.WaitForProcessFinished(_playCommand, null, null);
             if (res == ProcessHelper.PROCESS_EXECUTION_FAILED)
             {
                 throw new Exception("Ошибка выполнения процесса: " + _playCommand);
             }
         }
     }
     catch (ThreadAbortException)
     {
         Stop();
     }
     catch (Exception ex)
     {
         _logger.LogError(Message.SoundPlayError, ex, (string)state);
     }
     finally
     {
         if (_playCommand != null)
         {
             PlayingStopped.RaiseEvent(this);
         }
         _playCommand = null;
     }
 }
Exemplo n.º 5
0
 protected virtual void OnPlayingStopped()
 {
     PlayingStopped?.Invoke(this, new PlayAudioUpdatePositionEventArgs(this.AudioReader));
 }