Beispiel #1
0
        public void PausePlaySound()
        {
            if (IsMusicPlaying())
            {
                switch (playbackState)
                {
                case CustomPlayBackState.Playing:
                    int fadeOutTime = fadingValues[FadingActions.PlayPause]["fadeOut"];
                    if (fadeOutTime > 0)
                    {
                        playbackState = CustomPlayBackState.Pausing;
                        sampleProvider.BeginFadeOut(fadeOutTime);
                        PauseAndExecuter.Execute(delegate
                        {
                            if (playbackState == CustomPlayBackState.Pausing)
                            {
                                waveOutDevice.Pause();
                                playbackState = CustomPlayBackState.Paused;
                            }
                        }, fadeOutTime + 100);
                    }
                    else
                    {
                        waveOutDevice.Pause();
                        playbackState = CustomPlayBackState.Paused;
                    }
                    NewNotification("Paused :", currentTrackPlayed);
                    break;

                case CustomPlayBackState.Pausing:
                    PauseAndExecuter.AbortLast();
                    goto case CustomPlayBackState.Paused;

                case CustomPlayBackState.Paused:
                    playbackState = CustomPlayBackState.Playing;
                    int fadeInTime = fadingValues[FadingActions.PlayPause]["fadeIn"];
                    if (fadeInTime > 0)
                    {
                        sampleProvider.BeginFadeIn(fadeInTime);
                    }
                    else
                    {
                        sampleProvider.FadeState = FadeState.FullVolume;
                    }
                    waveOutDevice.Play();
                    NewNotification("Unpaused :", currentTrackPlayed);
                    break;
                }
            }
        }
Beispiel #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;
                }
            }
        }
Beispiel #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 { }
 }
Beispiel #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));
     }
 }