steveh
Topic Author
Posts: 25
Joined: 07 Oct 2019, 12:50

Issuing actions from storyboards

24 Oct 2019, 13:00

Hi guys,

I have been asked to look into creating a nice way of issuing UI audio events directly from storyboards. Some of our storyboards are quite elaborate and may take seconds to finish and have quite a lot of "jazz". The audio needs to match up to the UI animations, so it feels natural to do this directly within Blend.

I've not used actions yet, but it feels like a perfect solution for this. I intend to create actions to fire a 1 shot event, start an audio sound and to stop an audio sound. This is conceptually good, but I can't think of a good way to work with the timeline. Obviously there are no triggers so I can't rely on a trigger event. I suppose I could use a property trigger but this feels a little messy. I could use a timer event from the start of the storyboard event, but again, this feels like it may get out of sync with the timeline. Is there any nice way of interacting with triggers directly from the storyboard timeline? Ideally, I'd just like to have a "keyframe trigger" or something, where I could trigger an event at a given keyframe. Does this sound reasonable? How would I go about doing this?

Strangely, I've found very little information about how I would go about doing this in WPF so it feels like I'm trying to do something fundamentally incorrect. Any advice / guidance would be much appreciated.

Cheers,

-Steven
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: Issuing actions from storyboards

25 Oct 2019, 13:55

From what I understand you want to play sounds at a specific time during the duration of a storyboard animation, not triggered when the storyboard ends.

A storyboard can only change property values or notify when it is completed, so the two options I see for what you want are:
  • Trigger a play sound action on property value changes generated by the animation.
    <Storyboard Duration="0:0:10">
      ...
      <BooleanAnimationUsingKeyFrames Storyboard.TargetName="SoundTarget" Storyboard.TargetProperty="(UIElement.IsEnabled)">
        <DiscreteBooleanKeyFrame KeyTime="0:0:2.3" Value="True"/>
      </BooleanAnimationUsingKeyFrames>
    </Storyboard>
    ...
    <Decorator x:Name="SoundTarget" IsEnabled="False">
      <i:Interaction.Triggers>
        <ei:DataTrigger Binding="{Binding IsEnabled, ElementName=SoundTarget}" Value="True">
          <ei:PlaySoundAction Source="sound.wav"/>
        </ei:DataTrigger>
      </i:Interaction.Triggers>
    </Decorator>
  • Fire different Storyboards with the corresponding duration so you can trigger the sound when they complete, but I don't think this option has any advantage over the other one.
I want to remark also that the default PlaySoundAction is very limited because it can only be used to play a sound and nothing else. You probably want to create a more advanced action that allows you to control the sound: play, pause, resume, loop, fade volume...
 
steveh
Topic Author
Posts: 25
Joined: 07 Oct 2019, 12:50

Re: Issuing actions from storyboards

25 Oct 2019, 14:05

Cheers, yeah, it's as I expected. I think I'll go for choosing to trigger an action on the property changed event. I had hoped that there would be a simpler way which integrates with the timeline a little nicer, but this will do.

I expected that I would need to create some new actions. I don't mind generating all the required actions so we have better control over the audio events.

Thanks again.

-Steven

Who is online

Users browsing this forum: No registered users and 0 guests