Пример #1
0
    /// <summary>
    /// This method populates the <see cref="DESAudioPlayer"/> with the
    /// audio files that are called in the current trial at the
    /// correct starting times, so that they could be played and seeked along with the
    /// replay visualization.
    /// </summary>
    /// <param name="trialEvents">The complete <see cref="SortedList{Int32, TrialEvent}"/>
    /// of trial events to be parsed for audio stimuli.</param>
    /// <returns><strong>True</strong> if successful, otherwise <strong>false</strong>.</returns>
    protected bool LoadAudioStimuli(SortedList<int, TrialEvent> trialEvents)
    {
      try
      {
        if (this.currentTrial == null)
        {
          return false;
        }

        // Initialize player
        if (this.audioPlayer != null)
        {
          this.audioPlayer.Close();
          this.audioPlayer = null;
        }

        List<long> slideStartTimes = new List<long>();
        slideStartTimes.Add(0);
        List<TrialEvent> audioEvents = new List<TrialEvent>();

        foreach (TrialEvent trialEvent in trialEvents.Values)
        {
          if (trialEvent.Type == EventType.Slide)
          {
            slideStartTimes.Add(trialEvent.Time);
          }

          if (trialEvent.Type == EventType.Audio)
          {
            audioEvents.Add(trialEvent);
          }
        }

        for (int i = 0; i < this.currentTrial.Count; i++)
        {
          Slide slide = this.currentTrial[i];

          // Background sound
          if (slide.BackgroundSound != null && slide.BackgroundSound.ShouldPlay)
          {
            // Create only if needed
            if (this.audioPlayer == null)
            {
              this.audioPlayer = new DESAudioPlayer();
            }

            this.audioPlayer.AddSoundAtPosition(slide.BackgroundSound.FullFilename, slideStartTimes[i]);
          }

          // Parse elements for audio
          foreach (VGElement element in slide.VGStimuli)
          {
            if (element.Sound != null && element.Sound.ShouldPlay && !element.Sound.ShowOnClick)
            {
              // Create only if needed
              if (this.audioPlayer == null)
              {
                this.audioPlayer = new DESAudioPlayer();
              }

              this.audioPlayer.AddSoundAtPosition(element.Sound.FullFilename, slideStartTimes[i]);
            }
          }
        }

        // Parse elements for audio
        foreach (TrialEvent audioEvent in audioEvents)
        {
          string filename = Path.Combine(
            Document.ActiveDocument.ExperimentSettings.SlideResourcesPath,
            Path.GetFileName(Path.GetFileName(audioEvent.Param)));

          // Create only if needed
          if (this.audioPlayer == null)
          {
            this.audioPlayer = new DESAudioPlayer();
          }

          this.audioPlayer.AddSoundAtPosition(filename, audioEvent.Time);
        }

        // Initialize audioplayer for replay on time.
        if (this.audioPlayer != null)
        {
          this.audioPlayer.Initialize();
        }
      }
      catch (Exception ex)
      {
        ExceptionMethods.HandleException(ex);

        return false;
      }

      return true;
    }
Пример #2
0
    ///////////////////////////////////////////////////////////////////////////////
    // Construction and Initializing methods                                     //
    ///////////////////////////////////////////////////////////////////////////////
    #region CONSTRUCTION

    /// <summary>
    /// Initializes a new instance of the FormWithPicture class.
    /// </summary>
    public FormWithPicture()
    {
      this.audioPlayer = new DESAudioPlayer();
    }