I am trying to play a sound with my animation. I already have a working animation using a StoryBoard and DoubleAnimation. Does anyone know how to add a sound to that?
Microsoft documentation suggests using a MediaTimeline class:
There are two ways to associate a Timeline to a MediaElement using a MediaTimeline:
Inside of a Storyboard, when a MediaTimeline is targets [sic] a MediaElement, a MediaClock will be created and assigned to the MediaElement’s associated player. See How to: Control a MediaElement by Using a Storyboard for an example;
By explicitly creating a MediaClock from a MediaTimeline and assigning it to a MediaElement.
Stack Overflow answers also suggest using MediaTimeline.
Problem is that MediaTimeline class does not exist in Windows.Media namespace for UWP.
My animation code looks like this:
DoubleAnimation animX = new DoubleAnimation();
DoubleAnimation animY = new DoubleAnimation();
animX.Duration = TimeSpan.FromMilliseconds(600);
animY.Duration = TimeSpan.FromMilliseconds(800);
animX.From = pStart.X;
animX.To = pEnd.X;
animY.From = pStart.Y;
animY.To = pEnd.Y;
Storyboard StarStoryboard = new Storyboard();
Storyboard.SetTarget(animX, this.MyImage);
Storyboard.SetTargetProperty(animX, "(Canvas.Left)");
Storyboard.SetTarget(animY, this.MyImage);
Storyboard.SetTargetProperty(animY, "(Canvas.Top)");
StarStoryboard.Children.Add(animX);
StarStoryboard.Children.Add(animY);