Пример #1
0
 public void DoSeekFadeOut(int fadeOutTime)
 {
     if (fadingOutWaveOutDevice != null)
     {
         fadingOutWaveOutDevice.Stop();
     }
     if (playbackState == CustomPlayBackState.Playing)
     {
         fadingOutAudioFileReader = new AudioFileReader(currentTrackPlayed)
         {
             Volume   = audioFileReader.Volume,
             Position = audioFileReader.Position
         };
         fadingOutSoundTouch = new SoundTouch();
         SetSoundTouchSettings(fadingOutSoundTouch, fadingOutAudioFileReader, true);
         fadingOutSampleProvider = new CustomSampleProvider(fadingOutAudioFileReader, fadingOutSoundTouch);
         fadingOutWaveOutDevice  = new DirectSoundOut(currentAudioDevice, AudioLatency);
         fadingOutWaveOutDevice.Init(fadingOutSampleProvider);
         IWavePlayer          thisFadingOutWave         = fadingOutWaveOutDevice;
         CustomSampleProvider thisFadeOutSampleProvider = fadingOutSampleProvider;
         thisFadingOutWave.PlaybackStopped += delegate { thisFadeOutSampleProvider.Dispose(); thisFadingOutWave.Dispose(); fadingOutWaveOutDevice = null; };
         thisFadingOutWave.Play();
         fadingOutSampleProvider.BeginFadeOut(fadeOutTime, thisFadingOutWave);
     }
 }
Пример #2
0
        public void StopSound(bool fromNewSound = false)
        {
            if (IsMusicPlaying())
            {
                int fadeOutTime = fromNewSound ? fadingValues[FadingActions.StartSound]["fadeOut"] : fadingValues[FadingActions.Stop]["fadeOut"];
                switch (playbackState)
                {
                case CustomPlayBackState.Pausing:
                    PauseAndExecuter.AbortLast();
                    goto case CustomPlayBackState.Playing;

                case CustomPlayBackState.Playing:
                    if (fadeOutTime > 0)
                    {
                        IWavePlayer          currentWaveOut  = waveOutDevice;
                        CustomSampleProvider currentProvider = sampleProvider;
                        playbackState = CustomPlayBackState.Stopping;
                        currentWaveOut.PlaybackStopped += delegate
                        {
                            if (playbackState == CustomPlayBackState.Stopping)
                            {
                                playbackState = CustomPlayBackState.Stopped;
                            }
                            currentProvider.Dispose();
                            currentWaveOut.Dispose();
                        };
                        sampleProvider.BeginFadeOut(fadeOutTime, currentWaveOut);
                    }
                    else
                    {
                        CloseWaveOut();
                    }
                    break;

                case CustomPlayBackState.Paused:
                    CloseWaveOut();
                    break;
                }
            }
        }
Пример #3
0
 public void CloseWaveOut()
 {
     try
     {
         if (waveOutDevice != null)
         {
             waveOutDevice.Stop();
             playbackState = CustomPlayBackState.Stopped;
         }
         if (sampleProvider != null)
         {
             sampleProvider.Dispose();
             sampleProvider  = null;
             audioFileReader = null;
         }
         if (waveOutDevice != null)
         {
             waveOutDevice.Dispose();
             waveOutDevice = null;
         }
     }
     catch { }
 }