I'm having an issue with playing a sound in animation when the animation is run multiple times (one after another, not in parallel).
The structure is:
<Window....>
<Window.Resources>
<Storyboard x:Key="App_Build">
....
<MediaTimeline FillBehavior="Stop" Storyboard.TargetName="Pong_Public_D_145_wav" Source="Pong-Public_D-145.wav" />
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button1">
<BeginStoryboard x:Name="App_Build_BeginStoryboard1" Storyboard="{StaticResource App_Build}"/>
</EventTrigger>
</Window.Triggers>
<Grid x:Name="LayoutRoot"....>
<MediaElement x:Name="Pong_Public_D_145_wav" UnloadedBehavior="Stop" Volume="1"..../>
<Button x:Name="button1" Content="App Start" ..../>
......
</Grid>
</Window>
[I've removed all layout properties for brevity, plus the storyboard has more animations for visuals (opacity, visibility, etc.)]
What happens is when I click the button the storyboard runs as expected every time (I see the visuals change) but the sound is sometimes played and sometimes not.
I was not able to find any "rule" to when the sound is played. Sometimes it's played on first run, sometimes not. Sometimes it's playing 10 times in a row, sometimes it's not playing for 10 times. Sometimes it's playing on every alternating run (play -> no play -> play -> no play...).
The reason for multiple runs: this is a concept for the actual application, I need to present it to the client for them to approve it. They will want to see the animation multiple times, and the sound should play every time - it's an integral part of the whole animation.
I'm really stumped here, would like to hear any suggestion, in any direction.