Exemplo n.º 1
0
 private void btnPausePlay_Click(object sender, RoutedEventArgs e)
 {
     // StopWatch();
     if (output != null)
     {
         if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing)
         {
             output.Pause();
             stopWatch.Stop();
         }
         else if (output.PlaybackState == NAudio.Wave.PlaybackState.Paused)
         {
             output.Play();
             stopWatch.Start();
         }
     }
 }
Exemplo n.º 2
0
        public void DoPlay()
        {
            try
            {
                Console.WriteLine();
                Console.WriteLine("playing track. press space to play/pause; ESC to stop");
                System.Threading.Thread.Sleep(1000);

                NAudio.Wave.WaveOutEvent   wavout    = new NAudio.Wave.WaveOutEvent();
                NAudio.Wave.WaveFileReader wavreader = new NAudio.Wave.WaveFileReader(_beatFile.GetWavFilename());

                wavout.Init(wavreader);
                wavout.Play();

                int index = 0;
                List <BeatInstance> bl = _beatFile.GetAllBeats();

                while (wavout.PlaybackState != NAudio.Wave.PlaybackState.Stopped)
                {
                    if (System.Console.KeyAvailable)
                    {
                        switch (System.Console.ReadKey(true).Key)
                        {
                        case ConsoleKey.Spacebar:
                            if (wavout.PlaybackState == NAudio.Wave.PlaybackState.Paused)
                            {
                                wavout.Play();
                            }
                            else if (wavout.PlaybackState == NAudio.Wave.PlaybackState.Playing)
                            {
                                wavout.Pause();
                            }
                            break;

                        case ConsoleKey.Escape:
                            Console.WriteLine("stopped playback");
                            wavout.Stop();
                            break;

                        case ConsoleKey.OemPeriod:
                            Console.WriteLine("{0}", wavreader.CurrentTime.TotalSeconds);
                            break;
                        }
                    }

                    while (index < bl.Count && bl[index].TriggerTime <= wavreader.CurrentTime.TotalSeconds)
                    {
                        if (!_playQuiet)
                        {
                            ViewOneBeat(bl[index]);
                        }

                        index++;
                    }

                    System.Threading.Thread.Sleep(10);
                }

                wavout.Dispose();
                wavreader.Dispose();
            }
            catch (Exception ex)
            {
                throw new Exception("error playing track", ex);
            }
        }