コード例 #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;
                }
            }
        }
コード例 #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;
                }
            }
        }