Exemple #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);
     }
 }
Exemple #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;
                }
            }
        }
Exemple #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 { }
 }
Exemple #4
0
 public void PlaySound(string files, Guid audioDevice, int timeStart, float volume)
 {
     try
     {
         if (!CheckFiles(files))
         {
             throw new AudioFileMissingOrInvalidException(files);
         }
         StopSound(true);
         // files' paths separated by a *
         if (files.Contains("*"))
         {
             if (tracksOrdered == null || currentTracksList != files)
             {
                 currentTracksList = files;
                 OrderTracks();
             }
             files = GetTrack();
         }
         else
         {
             tracksOrdered = null;
         }
         audioFileReader        = new AudioFileReader(files);
         currentTrackPlayed     = files;
         waveOutDevice          = new DirectSoundOut(audioDevice, AudioLatency);
         currentAudioDevice     = audioDevice;
         currentVolume          = volume;
         audioFileReader.Volume = muted ? 0.0f : currentVolume;
         soundTouch             = new SoundTouch();
         SetSoundTouchSettings(soundTouch, audioFileReader);
         if (ResetAutoRepeat)
         {
             autoRepeat = false;
         }
         sampleProvider = new CustomSampleProvider(audioFileReader, soundTouch, autoRepeat);
         waveOutDevice.Init(sampleProvider);
         if (timeStart > 0 && timeStart < audioFileReader.TotalTime.TotalSeconds)
         {
             audioFileReader.Skip(timeStart);
             sampleProvider.StartingTime = timeStart;
         }
         int fadeInTime = fadingValues[FadingActions.StartSound]["fadeIn"];
         if (fadeInTime > 0)
         {
             sampleProvider.BeginFadeIn(fadeInTime);
         }
         waveOutDevice.Play();
         playbackState = CustomPlayBackState.Playing;
         NewNotification("Playing :", files);
     }
     catch (AudioFileMissingOrInvalidException ex)
     {
         MessageBox.Show(ex.MessageToUser, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format(ErrorHelper.UnexpectedErrorPlayback, files), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Logger.NewLog(ex, string.Format("Unknown playback Error. Files : \"{0}\" | Guid : \"{1}\" | Timestart : \"{2}\" | Volume : \"{3}\".", files, audioDevice.ToString(), timeStart, volume));
     }
 }