コード例 #1
0
 public void SkipSound(int timeValue)
 {
     try
     {
         if (audioFileReader != null && playbackState == CustomPlayBackState.Playing && waveOutDevice.PlaybackState == PlaybackState.Playing)
         {
             int fadeOutTime, fadeInTime;
             fadeOutTime = fadingValues[FadingActions.ForwardBackward]["fadeOut"];
             fadeInTime  = fadingValues[FadingActions.ForwardBackward]["fadeIn"];
             if (fadeOutTime > 0)
             {
                 DoSeekFadeOut(fadeOutTime);
             }
             audioFileReader.Skip(timeValue);
             if (fadeInTime > 0)
             {
                 sampleProvider.BeginFadeIn(fadeInTime);
             }
         }
     }
     catch (Exception ex) { Logger.NewLog(ex); }
 }
コード例 #2
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));
     }
 }