This project is read-only.

Variable slide durations

Feb 7, 2011 at 4:00 PM

I'm wondering how to adjust the slide duration based on the image name.  I have a normal looping slideshow of pictures, but every so often there is an image that has text on it so I want to increase the duration so users have time to read the text.  My images with text are named *_text.jpg.

Feb 8, 2011 at 8:44 PM

I do not know how to accomplish what you are asking but have an alternate suggestion.

Instead of putting text on the img, place the text on the description field. You can then have the img pause when the mouse hovers and/or just let visitors click the pause button.

This gives viewing control to the visitor which is usually a good practice. If the visitor feels in control, they are more likely to stick around and view your content.

Feb 8, 2011 at 9:42 PM

My situation actually doesn't involve any user interaction.  We have a TV in the hallway that's continuously running a slideshow.  For the most part, it's a slideshow of employee pictures, but occasionally we'll have some event announcements or something text related to post.  So since there's no user interaction possible to pause the slideshow I was looking for a way to at least customize the wait time to give a passerby more time to read the content of that slide. 

Anyway, I was actually able to do what I originally asked about, so I'll post my modifications in case someone else is looking for the same.  Thanks anyway, Brad!

What I did was add a waittime attribute to the slide element in the xml file.  Then I changed the TransitionManager to look to this property for the WaitTime instead of the Configuration options.

First, in Data.cs:

In the Data class, add a constant variable for your WaitTime to use as default wait time in case one isn't specified for the slide in Data.xml

public class Data
{
        // ...

        /// <summary>
        /// The wait time used in case no global or individual wait time is specified.
        /// </summary>
        public const int WAIT_TIME = 3000;

        // ...
}

Then, in the Slide class, add a int variable with get/set to hold the value for the WaitTime of the slide

public class Slide
{
        // ...

        /// <summary>
        /// Gets or sets the wait time.
        /// </summary>
        /// <value>The wait time.</value>
        public int WaitTime { get; set; }

        // ...
}

Second, in DataHandler.cs:

In the SlideHandler class, add the int variable with get/set for WaitTime as well and initialize the variable in the constructor.

public class SlideHandler
{
        // ...

        
        /// <summary>
        /// Gets or sets the wait time.
        /// </summary>
        /// <value>The wait time.</value>
        public int WaitTime { get; set; }

        // ...

        /// <summary>
        /// Initializes a new instance of the <see cref="SlideHandler"/> class.
        /// </summary>
        /// <param name="slide">The slide.</param>
        public SlideHandler(Slide slide)
        {
                // ...
                WaitTime = slide.WaitTime;
                // ...
        }

        // ...
}

Third, in XmlDataProvider.cs:

When reading the Data.xml file, grab the waittime attribute value and assign it to the Slide's WaitTime variable.  If there isn't a waittime attribute in Data.xml for the slide, then use the constant that we assigned in the Data class.

/// <summary>
/// parses the slides
/// </summary>
/// <param name="reader">the xmlreader</param>
/// <param name="inheritTransition">a string</param>
/// <returns>a Slide array</returns>
private Slide[] ParseSlides(XmlReader reader, string inheritTransition)
{
        List<Slide> slides = new List<Slide>();

        while (reader.Read())
        {
	if (reader.IsStartElement() && reader.Name == "slide")
	{
	        slides.Add(new Slide()
	        {
                        Title = reader.GetAttribute("title"),
                        // ...
                        WaitTime = reader.GetAttribute("waittime") != null ?
                            Convert.ToInt32(reader.GetAttribute("waittime")) : Data.WAIT_TIME
	        });
	}
        }
        return slides.ToArray();
}
Finally, in TransitionManager.cs:
In the constructor for the TransitionManager class, change it so the WaitTime is assigned from the Slide value instead of the configuration options.  This assigns the WaitTime for the first slide only.
/// <summary>
/// Initializes a new instance of the <see cref="TransitionManager"/> class.
/// </summary>
public TransitionManager()
{
        // ...

        WaitTime = album.Slides[ToSlideIndex].WaitTime; 
        // WaitTime = Configuration.Options.Transition.WaitTime;

        // ...

        // Transition into first slide:
        TaskStack.Push(new TransitionTask(0, 0, null, 0, true));
}
 
To use the WaitTime for each slide, scroll down to the ExecuteNextTask() method and modify the line where a WaitTask is pushed onto the TaskStack. 
Instead of always passing the WaitTime that we assigned in the constructor above, pass in the WaitTime from the next Slide
 
/// <summary>
/// Executes the next task.
/// </summary>
private void ExecuteNextTask()
{
        if (!TaskStack.Peek().IsPrioritizedInput)
        {
                if (TaskStack.Peek() is TransitionTask)
                {
                        if (lastTransitionEventArgs.ToSlide is VideoViewer)
                        {			                
                                // SlideShow will continue when media finishes playing
                                Pause();
                        }

                	      TaskStack.Pop();
                        TaskStack.Push(new WaitTask(album.Slides[ToSlideIndex].WaitTime, false));
                	      //TaskStack.Push(new WaitTask(WaitTime, false));
				
                }
                else
                {
                        // ...
                }
        }

        // ...
}
Mar 2, 2011 at 1:19 PM

Very useful.  I've actually been working on this exact solution and here it is, just "falling in my lap" so to speak.

 

Thanks for posting.